]>
Commit | Line | Data |
---|---|---|
a8f35baf CMB |
1 | #!/usr/bin/env python |
2 | ||
3 | import socket, struct | |
4 | ||
5 | def get_default_gateway_linux(): | |
6 | """Read the default gateway directly from /proc.""" | |
7 | with open("/proc/net/route") as fh: | |
8 | for line in fh: | |
9 | fields = line.strip().split() | |
10 | if fields[1] != '00000000' or not int(fields[3], 16) & 2: | |
11 | continue | |
12 | ||
13 | return socket.inet_ntoa(struct.pack("<L", int(fields[2], 16))) | |
14 | ||
15 | print socket.gethostbyaddr(get_default_gateway_linux())[0] | |
16 |