简体   繁体   English

使用 Scapy 查找 LAN 路由器 IP 地址?

[英]Find LAN router IP address with Scapy?

I am attempting to find my router's IP address with Scapy .我正在尝试使用Scapy查找路由器的 IP 地址。

I am running a distro of Linux and fully understand that I could use system calls or subprocess to get to the routing tables and find the gateway.我正在运行 Linux 发行版,并且完全理解我可以使用系统调用或子进程来访问路由表并找到网关。 However, I am trying to do this without system calls.但是,我正在尝试在没有系统调用的情况下执行此操作。

I imagine there is a way to do there is a way to do this with Scapy, does anyone know?我想有一种方法可以用 Scapy 做到这一点,有人知道吗?

FTR, see https://scapy.readthedocs.io/en/latest/routing.html FTR,见https://scapy.readthedocs.io/en/latest/routing.html

Get router IP address获取路由器IP地址

>>> gw = conf.route.route("0.0.0.0")[2] >>> gw '10.0.0.1'

I used the knowledge that if i send a packet to a distant IP adress with ttl = 0, I will get an ICMP packet from the first router i pass(my default gateway), all i'll need to do later is get the IP from that packet我使用的知识是,如果我将数据包发送到 ttl = 0 的远程 IP 地址,我将从我通过的第一个路由器(我的默认网关)获得一个 ICMP 数据包,我稍后需要做的就是获取 IP从那个包

from scapy.all import *
p = sr1(IP(dst="www.slashdot.org", ttl = 0)/ICMP()/"XXXXXXXXXXX")
print p.src

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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