1
votes

I don't know what I'm doing wrong. There are no errors or anything, It just keeps saying I'm not registered. This is also an IRC channel and network that does not require registering nicks to use. Thanks in advance.

#I've set variables and imported stuff up here
socket.connect((host, port))
socket.recv(512)
socket.send('NICK %s' % (username))
socket.send('USER %s %s %s :%s\r\n' % (username, username, username, username))
pingPong = socket.recv(512)
print pingPong
pingPong = pingPong[5:]
print 'PONG ' + pingPong
socket.send('PONG %s\r\n' % pingPong)
print 'PONG ' + host + '\r\n'
time.sleep(5) #I even added this time.sleep() to wait for the PONG to go through.
socket.send('JOIN %s\r\n' % channel)
socket.recv(1024)
#I have a while loop that continually receives data and commands down here

This outputs:

PING :912E235B

PONG :912E235B

:irc.va.us.mibbit.net 451 JOIN :You have not registered

1

1 Answers

2
votes

Your NICK and USER commands are malformed. NICK should have an "\r\n" at the end. USER should not just be your username 4 times. Below is a working connection to that irc server.

import socket

host = "irc.va.us.mibbit.net"
port = 6667
username = "andrew"
channel = "luck"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
print "recv 1", s.recv(512)
s.send('NICK %s\r\n' % (username,))
s.send('USER %s 8 * :%s\r\n' % (username, username))
pingPong = s.recv(512)
print "recv 2", pingPong
pingPong = pingPong[5:]
s.send('PONG %s\r\n' % pingPong)
s.send('JOIN %s\r\n' % (channel,))
msg = s.recv(1024)
print "Message", msg