Getting a machine’s external IP address with Python Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Getting a machine’s external IP address with Python without wasting too much if your time.

The question is published on by Tutorial Guruji team.

Looking for a better way to get a machines current external IP #… Below works, but would rather not rely on an outside site to gather the information … I am restricted to using standard Python 2.5.1 libraries bundled with Mac OS X 10.5.x

import os
import urllib2

def check_in():

    fqn = os.uname()[1]
    ext_ip = urllib2.urlopen('http://whatismyip.org').read()
    print ("Asset: %s " % fqn, "Checking in from IP#: %s " % ext_ip)

Answer

If you are behind a router which obtains the external IP, I’m afraid you have no other option but to use external service like you do. If the router itself has some query interface, you can use it, but the solution will be very environment-specific and unreliable.

We are here to answer your question about Getting a machine’s external IP address with Python - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji