我尝试从Scapy路由表中删除一条路由,但没有成功。这是我的桌子:
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
我尝试了这个命令:
conf.route.delt(net="192.168.3.1/32",gw="0.0.0.0")
得到了这个错误:
ValueError("No matching route found!")
知道可能是什么问题吗?
当我运行像你这样的代码时,在完整的错误消息中,我可以看到
ValueError: (3232236289, 4294967295, '0.0.0.0', 'enp0s8', '10.0.0.1', 1) is not in list
所以我开始检查源代码,发现我可以使用
conf.route.routes
查看不同格式的路由表-作为元组列表
[(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)]
当我将其与错误消息中的值进行比较时,我发现它们对metric
(元组中的最后一个值(有不同的值。表具有20100
,但错误显示为1
。
如果我在delt
中添加metric
,代码对我有效
conf.route.delt(net="192.168.3.1/32", gw="0.0.0.0", metric=20100)
编辑:
这也允许使用索引删除路线,即删除表中的最后一项
del(conf.route.routes[-1])