The source code for a Python program (The language not the snake.) that will fetch the
dotted decimal IP address of a website of your choice and convert it in to a valid 32 bit
one as show in the other write-ups. You will need Python and the module found at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/111286 to get it to run. I hope you
find this useful (This may not be the best way to do it Im still learning python. :-)
There may be are formatting errors sorry about that, Im new to Everything.
#Written by Hexice hectorDOTdearmanATgoogleDotcom
#Note nslookup
#Note http://everything2.com/index.pl?node=IP%20address
#Note http://everything2.com/index.pl?node_id=951857&lastnode_id=0
#For converting from decimal to binary and back.
import BaseConvert
#For geting the IP address.
from socket import gethostbyname
#The help text.
DotDecto32bithelp = """ This was written mainly to see if I could however
it does have a practical application, it converts
dotted decimal IP address's (64.233.183.103) in
to 32-bit decimal format (1089058663) which can
be used as a valid internet address (In this case Google).
The main reason you would want to do this would
be to get past censorship programs on school,
library or workplace computers.
For more information
go to http://everything2.com/index.pl?node=IP%20address
or http://everything2.com/index.pl?node_id=951857&lastnode_id=0
Im am indebted to Drew Perttula for creating the
module BaseConvert (which funnily enough is used to
covert between bases.)
Note: If you wish to find out the IP address of
a website on a windows operating system go to
start > all programs > Accessories > Command prompt
then type: nslookup [web site who’s IP address you want]
The program will now print out the Google 32-bit
address run it again to find a diffrent 32-bit
address, I hope this program is usefull to you.
By Hexice hectorDOTdearmanATgoogleDotcom
Update: this program will now (attempt) to fetch the
IP address from a website you give it, be warned however
this is far from stable.
"""
#Variables, shown here for clarity.
webaddress = 'www.google.com'
RawIPaddress = '000.000.000.000'
IPaddress = ['000','000','000','000']
IPaddressRawbinary = ['00000000','00000000','00000000','00000000']
IPaddressbinary = ['00000000','00000000','00000000','00000000']
IPaddressbinarystring = '00000000000000000000000000000000'
DecimalIPaddress = '0000000000'
error = ''
#Print the intro and ask for the web address
print 'This program will find the 32 bit address for a website.'
print 'Input a website below or type help for help or type IP,'
print 'if you wish to cut to the chase and input an IP address'
print 'you all ready know.'
print
webaddress = raw_input('>')
if webaddress == 'IP':
#Ask for the dotted decimal IP address.
print "Please input IP address (Dotted decimal form.) or type help for help"
RawIPaddress = raw_input('>')
elif webaddress == 'help':
print DotDecto32bithelp
# The Google IP address, the rest of the program will now execute.
RawIPaddress = '64.233.183.103'
else:
#Gets the IP address.
RawIPaddress = gethostbyname(webaddress)
#Print the help if thats what the user asked for.
if RawIPaddress == 'help':
print DotDecto32bithelp
# The Google IP address, the rest of the program will now execute.
RawIPaddress = '64.233.183.103'
elif RawIPaddress == 'this':
print
import this
print
RawIPaddress = '64.233.183.103'
else:
pass
#Split the IP address into component parts.
IPaddress = RawIPaddress.rsplit('.')
#Convert the decimal numbers to binary.
try:
IPaddressRawbinary[0] = BaseConvert.baseconvert(IPaddress[0],BaseConvert.BASE10,BaseConvert.BASE2)
IPaddressRawbinary[1] = BaseConvert.baseconvert(IPaddress[1],BaseConvert.BASE10,BaseConvert.BASE2)
IPaddressRawbinary[2] = BaseConvert.baseconvert(IPaddress[2],BaseConvert.BASE10,BaseConvert.BASE2)
IPaddressRawbinary[3] = BaseConvert.baseconvert(IPaddress[3],BaseConvert.BASE10,BaseConvert.BASE2)
#See if an index error has occurred.
except IndexError:
#If there is an error tell the user.
print 'An Index Error has occurred,'
print 'you must input a IP address in dotted decimal form (i.e 64.233.183.103).'
#Create a second error massage that will be printed out when we get to displaying the address.
error = '[Index Error (see above)]'
#See if an value error has occurred.
except ValueError:
#If there is an error tell the user.
print 'A ValueError has occurred,'
print 'you must input a IP address in dotted decimal form (i.e 64.233.183.103).'
#Create an error massage that will be printed out when we get to displaying the address.
error = '[ValueError (see above)]'
else:
pass
#Pad out the binary with extra zeros so that every number is 8 digits long.
IPaddressbinary[0] = IPaddressRawbinary[0].zfill(8)
IPaddressbinary[1] = IPaddressRawbinary[1].zfill(8)
IPaddressbinary[2] = IPaddressRawbinary[2].zfill(8)
IPaddressbinary[3] = IPaddressRawbinary[3].zfill(8)
#Create a single string out of the binary IP address's.
IPaddressbinarystring = IPaddressbinary[0] + IPaddressbinary[1] + IPaddressbinary[2] + IPaddressbinary[3]
#Convert back to decimal.
DecimalIPaddress = BaseConvert.baseconvert(IPaddressbinarystring,BaseConvert.BASE2,BaseConvert.BASE10)
#Display the converted address and the error message (If there is one.).
print 'http://' + DecimalIPaddress + error