Last active
December 13, 2023 17:14
-
-
Save justinmassiot/6bd4e61c8b499b4d8036cf84b6fcbc75 to your computer and use it in GitHub Desktop.
Obtain the IP address of the designated interface (Linux systems)
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
import socket | |
def get_ipaddress(network='wlan0'): | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
return socket.inet_ntoa(fcntl.ioctl( | |
s.fileno(), | |
0x8915, # SIOCGIFADDR | |
struct.pack('256s', network[:15]) | |
)[20:24]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment