IP Address Finder

kmcdougald · updated November 25, 2022
def checkforip():
    import socket
    hostname = socket.gethostname()
    IPAddr = socket.gethostbyname(hostname)
    return(print("Host: " + hostname + " IP:" + IPAddr))


checkforip()

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("169.254.186.61", 80))
print(s.getsockname()[0])
s.close()
Output
(Run the program to view its output)

Comments

Please sign up or log in to contribute to the discussion.