Tag: ipchicken


by on Jan.18, 2010, under Code, Posts

If you are one of the very very few to remember a shell script that I wrote a while back that let’s you know your WAN IP address from the command line (ipchicken), I wrote a replacement for it in python. I hope this is useful to you:


#!/usr/bin/env python
import re
import urllib
import socket
import sys

#Test that ipchicken.com is up#
var = socket.socket()
        var.connect(('www.ipchicken.com', 80))
except socket.error:
        print "www.iphicken.com seems to be down.."

var = urllib.urlopen('http://www.ipchicken.com')
var = str(var.readlines())

reg = "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"

for ip in re.findall(reg, var):
        print """Your WAN IP address is: %s \nBrought to you by www.ipchicken.com""" % ip

Also, the beauty behind this, is that all you need is python and it should work on any operating system that supports python.

Of course, if you have dog for Linux, then you can get the same affect with just a quick one liner:

dog http://www.ipchicken.com | egrep -wo "[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}"


Leave a Comment : more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!