0

i am trying to connect to anonops irc server and subsequently #anonops channel using python. What i have done so far :

import sys
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
HOST = 'irc.anonops.com' #irc server
PORT = 6697 #port
NICK = 'testingbot'



print('soc created |', s)
remote_ip = socket.gethostbyname(HOST)
print('ip of irc server is:', remote_ip)


s.connect((HOST, PORT))

print('connected to: ', HOST, PORT)
nick_cr = ('NICK ' + NICK + '\r\n').encode()
s.send(nick_cr)
s.send('JOIN #anonops \r\n'.encode()) #chanel

#
s.send(bytes("PRIVMSG " + '#anonops' +  'hi'+ "\n", "UTF-8"))

I think this connect succesfuly to the irc server but i can't seem to connect to the channel. I have an open irc client (Hexchat) in my pc and i don't see the message:
testingbot has joined nor do i see the hi message.
Any idea about what am i doing wrong?

Los
  • 111
  • 6
  • 2
    you have to follow the IRC protocol. Right now you are making no attempt to actually speak the IRC protocol (except apparently you saw the word PRIVMSG somewhere), you are just sending / commands that are normally understood by your client. I won't answer by explaining the entirety of the IRC protocol because that would be too long of an answer - you can look it up. – user253751 Jan 12 '23 at 11:33
  • @user253751 The code was taken from [here](https://stackoverflow.com/questions/2968408/how-do-i-program-a-simple-irc-bot-in-python) and has supposedly worked for others. If i join another channel it works, there seems to be a specific problem with the current channel. Maybe some kind of anti-bot defense. – Los Jan 12 '23 at 14:12
  • but it's not the same code. They are sending USER and then NICK and also doing this recv and PING/PONG stuff. – user253751 Jan 12 '23 at 14:21
  • @user253751 Yeah i tried all that, still no response from the server. I get response from other irc servers though so i guess there is something wrong with this one. – Los Jan 12 '23 at 14:36
  • In this code you aren't doing all that. – user253751 Jan 12 '23 at 14:36

1 Answers1

0

Use remote_ip instead of HOST.

s.connect((remote_ip, PORT))

feature09
  • 74
  • 2
  • 7