someoneb100 someoneb100 - 5 months ago 18
Python Question

Making a program that checks external ip

I'd like to make a program for my Ubuntu that checks the external ip of the computer. My idea is to go to whatsmyip.org and print out what is written in the

span
with the
id=ip
in the Terminal. Writing the entire code is not necessary because i am doing this as an exercise (if you want to i won't stop you), but i don't know where to start so i'd appreciate some guidelines.

PHP, C, Python and Bash are my weapons of choice, so any advice involving these is welcome.

EDIT: I haven't explained well what i want. I want to learn how to fetch data from webites in programs. Checking the ip was just an idea how to try and learn it.

Answer

You should use DNS for this rather than HTTP for reliability's sake.

Opendns provides a meta-address, myip.opendns.com, that will be resolved to your global IP when resolved by their resolver(s).

In a nutshell, you can do:

dig myip.opendns.com @resolver1.opendns.com

Just the IP:

dig +short myip.opendns.com @resolver1.opendns.com
Comments