[英]Cant delete a route from Scapy's route table?
I tried deleting a route from a Scapy routing table with no success.我尝试从 Scapy 路由表中删除一条路由,但没有成功。 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).当我将它与错误消息中的值进行比较时,我看到它们具有不同的
metric
(元组中的最后一个值)。 Table has 20100
but error shows 1
.表有
20100
但错误显示1
。
Code works for me if I add metric
in delt
如果我在
delt
中添加metric
,代码对我有用
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])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.