irc.py
From Club Ubuntu
This is the absolute minimum functionality for an IRC program, such as a client or a bot. It will connect and then print anything it receives. You will presumably want to change the network and nick settings before running it.
Code
import socket
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect(('irc.freenode.net', 6667))
trash = irc.recv(4096)
irc.send('NICK nick\r\n')
irc.send('USER nick nick nick :realname\r\n')
while True:
data = irc.recv(4096)
if data.find('PING') != -1:
irc.send('PONG ' + data.split()[ 1 ] + '\r\n')
lines = data.split('\r\n')
for line in lines:
print line

