How to get IP address

Jorge Godoy godoy at
Thu Mar 6 02:14:48 CET 2003

Dennis Lee Bieber <wlfraed at> writes:

>         My dial-up address doesn't show at all (though the KPPP stats does 
> show both ends: local remote
>         Of course, I only have the one machine in place, no idea what would 
> result if I hooked my laptop to the ethernet card and tried from it.

I've made a really ugly hack as my first Python implementation of
something web related.

#! /usr/bin/env python
# Pattern we're looking for:
#        <h1 align="center"> Your IP address is<br>
#        </h1>
# Address:

import urllib
import re
import sys
from HTMLParser import HTMLParser

class ProcessContents(HTMLParser):
    def handle_data(self, data):
        # Debug
        # print data
        ip_address = re.compile("\d+\.\d+\.\d+\.\d+").search(data)
        if ip_address:

def start():
    # Open and read website...
    sock = urllib.urlopen('')
    pagina =
    process = ProcessContents()

if (__name__ == '__main__'):

I know I could do that in a much simpler way, but it was a toy to
attach to a bigger thing... It will show you your IP address that is
connected to the Internet.

See you,
Godoy.     <godoy at>

More information about the Python-list mailing list