Skip to content

Instantly share code, notes, and snippets.

@riverfor
Created July 29, 2017 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riverfor/d80b450536fe46a21708829921b04fc2 to your computer and use it in GitHub Desktop.
Save riverfor/d80b450536fe46a21708829921b04fc2 to your computer and use it in GitHub Desktop.
import socket
import fcntl
import struct
interfaces = [
b"eth0",
b"eth1",
b"eth2",
b"wlan0",
b"wlan1",
b"wifi0",
b"ath0",
b"ath1",
b"ppp0",
]
def getlan(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#print(ifname[:15])
print( socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))[20:24]) )
for int in interfaces:
getlan(int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment