A python script to check for listening port on remote machine.

January 21st, 2010

I recently wanted to make sure a port listening on a remote machine. I used python and put this together in a couple of minutes.

#!/usr/bin/python

import socket,os,smtplib,sys,time
counter = 0

def sendEmail(fr,to,body):
subject = body
m = “From: %s\r\nTo: %s\r\nSubject: %s\r\nX-Mailer: My-Mail\r\n\r\n” % (fr, to, subject)
server = smtplib.SMTP(’localhost’)
server.sendmail(fr, to, m+body)
server.quit()

def checkServer():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setblocking(3)
try:
s.connect((”server.com”,int(25)))
s.shutdown(2)
return 0
except:
return 1

sendEmail(”from@from.com”, “to@to”, “port.py starting…”)
pid = os.fork()
if pid == 0:
while(1):
time.sleep(9000)
status = checkServer()
if status == 1:
if counter >= 2:
sendEmail(”from@from.com”, “to@to”, “Error connecting to server.”)
else:
counter = counter + 1
else:
counter = 0
else:
while(1):
time.sleep(7200)
sendEmail(”from@from.com”, “to@to”, “port.py running…”)

More google and china.

January 14th, 2010

I have been reading a lot about Google and China. This is much more complicated than I first realized. Google’s entire business going forward is people putting their data in the cloud. If their data is in the cloud Google can learn about us. If they learn about us, advertisers can target us. This is what Google needs to do to make oodles and oodles of money. The internets cannot be a wild wild west for people to trust the cloud. This is a very well put together essay on it.

http://www.tnr.com/article/politics/gathering-clouds

Google bluffing in China?

January 13th, 2010

This must be a bluff by Google. I very good bluff, but a bluff none the less. There are too many people willing to click too many ads for a publishing company like Google to ignore.

http://googleblog.blogspot.com/2010/01/new-approach-to-china.html