Skip to content

Instantly share code, notes, and snippets.

@codedeep79
Last active April 9, 2022 10:03
Show Gist options
  • Select an option

  • Save codedeep79/9679537c4cc107ab5f724d9fe5d64fdc to your computer and use it in GitHub Desktop.

Select an option

Save codedeep79/9679537c4cc107ab5f724d9fe5d64fdc to your computer and use it in GitHub Desktop.
Get IP Address (only linux) in Python
def getIpAddress(self, ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(
fcntl.ioctl(s.fileno(), 0x8915, struct.pack("256s", ifname[:15]))[20:24]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment