[英]Cant delete a route from Scapy's route table?
我嘗試從 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])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.