简体   繁体   中英

Cant delete a route from Scapy's route table?

I tried deleting a route from a Scapy routing table with no success. This is my table:

    Network      Netmask          Gateway      Iface   Output IP  Metric
0.0.0.0      0.0.0.0          192.168.3.1  enp0s8  10.0.0.1   20100 
10.0.0.0     255.255.255.0    0.0.0.0      enp0s8  10.0.0.1   100   
127.0.0.0    255.0.0.0        0.0.0.0      lo      127.0.0.1  1     
169.254.0.0  255.255.0.0      0.0.0.0      enp0s8  10.0.0.1   1000  
192.168.3.1  255.255.255.255  0.0.0.0      enp0s8  10.0.0.1   20100

I tried this command:

conf.route.delt(net="192.168.3.1/32",gw="0.0.0.0")

and got this error:

ValueError("No matching route found!")

Any idea what might be the problem?

When I run code like yours then in full error message I can see

ValueError: (3232236289, 4294967295, '0.0.0.0', 'enp0s8', '10.0.0.1', 1) is not in list

So I start checkingsource code and I found that I can use

conf.route.routes

to see route table in different format - as list of tuples

[(2130706432, 4278190080, '0.0.0.0', 'lo', '127.0.0.1', 1),
 # ... other tuples ...
 (3232236289, 4294967295, '0.0.0.0', 'enp0s8', '10.0.0.1', 20100)]

When I compared it with value from error message the I saw they have different value for metric (last value in tuple). Table has 20100 but error shows 1 .

Code works for me if I add metric in delt

conf.route.delt(net="192.168.3.1/32", gw="0.0.0.0", metric=20100)

EDIT:

This allow also to delete route using index - ie to delete last item in table

del(conf.route.routes[-1])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM