Last active
April 9, 2022 10:03
-
-
Save codedeep79/9679537c4cc107ab5f724d9fe5d64fdc to your computer and use it in GitHub Desktop.
Get IP Address (only linux) in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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