简体   繁体   中英

Find LAN router IP address with Scapy?

I am attempting to find my router's IP address with Scapy .

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. 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?

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

Get router IP address

>>> 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

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

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