faqts : Computers : Programming : Languages : Python : Snippets

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

24 of 56 people (43%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

Detecting own computer's IP
How do I go about getting my dynamic IP address?

Jul 5th, 2000 10:01
Nathan Wallace, unknown unknown, Hans Nowak, Snippet 188, Python Snippet Support Team


"""
Packages: networking.sockets
"""
""" detectip.py
    Detects your own IP address. No big deal on Python; more work on Delphi
    (where the code originated from :).
"""
import socket
def detectip():
    buf = socket.gethostname()
    remotehost = socket.gethostbyname(buf)
    return remotehost
if __name__ == "__main__":
    print "Your IP address is", detectip()
    raw_input()