]> git.uio.no Git - uio-zabbix.git/blame - get_default_gateway
Use env python header + Upgrade code to support python3 [GID-1248]
[uio-zabbix.git] / get_default_gateway
CommitLineData
753b94ce 1#!/usr/bin/env python
a8f35baf
CMB
2
3import socket, struct
4
5def get_default_gateway_linux():
6 """Read the default gateway directly from /proc."""
aebff062
RM
7 fh = open("/proc/net/route")
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)))
a8f35baf 14
753b94ce 15print (socket.getfqdn(get_default_gateway_linux()))
2590be6c 16
a8f35baf 17