User:Silviolorusso/ipmosaic

From XPUB & Lens-Based wiki

IP Mosaic

IP Mosaic


What

A webpage that collects little squares whose colour is based on the IP Address of the visitor.

Ipmosaic.png


Code

#!/usr/bin/python
import os

print "Content-type:text/html; charset=utf-8"
print


#retrieve the IP Address
ipad =  os.environ['REMOTE_ADDR']
#split into 4 values
ipad = ipad.split('.')
#obtain a float value for the alpha
ipadalpha = float(ipad[3])

#print the taxel
div =  """

<div style="width:10px; height:10px; float:left; background:rgba({0}, {1}, {2}, {3})" >
</div>

""".format(ipad[0], ipad[1], ipad[2], (ipadalpha/255))

#open the txt file and append div
divs = open('divs.txt','a')
divs.write(div)



#print head of the html
print """

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>IP Mosaic</title>
</head>

<body style="margin:0">

"""

divs = open('divs.txt','r')
print divs.read()

print "</body>"