if fields[1] != '00000000' or not int(fields[3], 16) & 2:
    continue
return socket.inet_ntoa(struct.pack('<L', int(fields[2], 16)))
Python: get default gateway for a local interface/ip address in linux