Python IRC 机器人无法加入

发布于 2024-10-13 18:10:54 字数 1443 浏览 6 评论 0原文

我收到错误消息

:irc.evilzone.org 通知授权:* 查找您的主机名...

:irc.evilzone.org 通知授权:* 找到您的主机名(已缓存)

PING:7091A8FB

:irc.evilzone.org 451 加入 :你有 未注册

:irc.evilzone.org 451 PRIVMSG:你 还没有注册

server = "irc.evilzone.org" # Server 
port = 6667 #port connect through IRC standard is :(6667 or 9999)
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( server, port ) )
print irc.recv ( 4096 )
nick = 'Piebot' #bots name
chan = 'test' #channel
version= "1.0" #current version
irc.send ( 'NICK Pizebot\r\n' ) 
irc.send ( 'USER Pizebot Pibot Pibot :Python IRC\r\n' )
irc.send ( 'JOIN #test\r\n' ) # YOU MUST CHANGE THE CHANNEL HERE AND BELOW!!
irc.send ( 'PRIVMSG #test :Hello World.\r\n' )

while True:
    readbuffer= irc.recv(4096)

    temp=string.split(readbuffer, "\n")
    Check = readbuffer.split(':')
    print readbuffer

请记住,我使用的一些命令需要代码的 temp= string.split(readbuffer,"\n") 部分。但是使用这样的代码

network = 'irc.evilzone.org'
port = 6667
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( network, port ) )
print irc.recv ( 4096 )
irc.send ( 'NICK ipbot\r\n' )
irc.send ( 'USER ipbot completely real :Jxxx\r\n' )
irc.send ( 'JOIN #test\r\n' )
irc.send ( 'PRIVMSG #test:Oh Hai.\r\n' )
while True:
   data = irc.recv ( 4096 )

我可以成功连接到通道等。有什么想法吗?

I get the error message

:irc.evilzone.org NOTICE AUTH :* Looking up your hostname...

:irc.evilzone.org NOTICE AUTH :*
Found your hostname (cached)

PING :7091A8FB

:irc.evilzone.org 451 JOIN :You have
not registered

:irc.evilzone.org 451 PRIVMSG :You
have not registered

server = "irc.evilzone.org" # Server 
port = 6667 #port connect through IRC standard is :(6667 or 9999)
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( server, port ) )
print irc.recv ( 4096 )
nick = 'Piebot' #bots name
chan = 'test' #channel
version= "1.0" #current version
irc.send ( 'NICK Pizebot\r\n' ) 
irc.send ( 'USER Pizebot Pibot Pibot :Python IRC\r\n' )
irc.send ( 'JOIN #test\r\n' ) # YOU MUST CHANGE THE CHANNEL HERE AND BELOW!!
irc.send ( 'PRIVMSG #test :Hello World.\r\n' )

while True:
    readbuffer= irc.recv(4096)

    temp=string.split(readbuffer, "\n")
    Check = readbuffer.split(':')
    print readbuffer

Keeping in mind that some of the commands I use need the temp= string.split(readbuffer,"\n") portion of the code.But with code like this

network = 'irc.evilzone.org'
port = 6667
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( network, port ) )
print irc.recv ( 4096 )
irc.send ( 'NICK ipbot\r\n' )
irc.send ( 'USER ipbot completely real :Jxxx\r\n' )
irc.send ( 'JOIN #test\r\n' )
irc.send ( 'PRIVMSG #test:Oh Hai.\r\n' )
while True:
   data = irc.recv ( 4096 )

I can successfully connect to the channel etc. Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

染柒℉ 2024-10-20 18:10:54

我认为有两个可能的原因:

  • 您提前发送了命令。通常你需要等待一段时间才能完全建立连接并且服务器接受你的命令(尤其是 JOIN)。所以你需要先等待服务器响应(发送NICK命令后,在某个时刻你会收到MODE命令;之后你可以调用普通命令,包括JOIN)。
  • 另一种可能性是 PING,它可能不是真正的解决方案,但如果您想留在 IRC 服务器上,它仍然很重要。服务器随机发送PING命令。通常要求使用 PONG 命令进行响应(参数与接收到的 PING 相同)。否则服务器可能会踢你。

I see two possible reasons for that:

  • You are sending the commands to early. Usually you need to wait quite a while before the connection is completely established and the server accepts your commands (especially JOIN). So you need to wait for server responses first (after sending a NICK command, you get a MODE command back at some point; after that, you can call normal commands, including JOIN).
  • The other possibility, which might not be the real solution here but is still important if you want to stay on the IRC server, is the PING. The server randomly sends a PING command. You are usually required to respond with a PONG command (parameter the same as the received PING). Otherwise the server might kick you.
何时共饮酒 2024-10-20 18:10:54

我注意到您不处理 PING 请求,有些服务器在您回复 PING 请求之前不接受任何其他命令(因此未注册)。
您需要连接,然后是 NICK,检查 PING,然后是 USER,如果 USER 之前没有 PING,则再次检查 PING。

有些服务器喜欢在 NICK 之后发送,其他服务器则在 USER 之后发送。

PING :7091A8FB\r\n

要响应此 PING,只需发送:

PONG :7091A8FB\r\n

:'\r\n 之间将是一个随机字符串,您需要将其与 PONG 一起发送回来,如上所示。

I noticed that you do not handle PING requests, some servers do not accept any other commands until you have replied to the PING request (hence not registered).
You would want to connect, then NICK, check for a PING, then USER, check for PING again if there was none before USER.

Some servers like to send it after NICK, others after USER.

PING :7091A8FB\r\n

To respond to this PING, simply send:

PONG :7091A8FB\r\n

Between the : and '\r\n will be a random string that you need to send back with your PONG as shown above.

愁杀 2024-10-20 18:10:54

发送“USER ...”和“JOIN ...”之间的时间需要增加。我在 Bash 中执行相同代码时遇到了这个问题。我是这样做的:

#!/bin/bash
(
echo NICK bashscript
echo USER bashscript 8 \* : Centreon Notifier
sleep 2
# echo 'JOIN #netops'
echo 'PRIVMSG #netops' $1
echo QUIT
) | nc 127.0.0.1 6667

The time between sending "USER ..." and "JOIN ..." needs to be increased. I have encountered this issue while doing the same code in Bash. Here's how I did it:

#!/bin/bash
(
echo NICK bashscript
echo USER bashscript 8 \* : Centreon Notifier
sleep 2
# echo 'JOIN #netops'
echo 'PRIVMSG #netops' $1
echo QUIT
) | nc 127.0.0.1 6667
寒尘 2024-10-20 18:10:54

PING:7091A8FB

这是阻止您在 IRC 服务器上注册的问题。

虽然您(从技术上讲)应该能够使用 NICK/USER 组合在 IRC 上注册,但您在登录时收到的 PING 是当今大多数 IRC 服务器所采用的非常简单的 DoS 保护机制。

您需要按如下方式回复 ping:

PONG :7091A8FB

每次收到 PING 时,该字符串都应该更改。
稍后您还会收到 PING 请求以确保连接仍然有效,因此编写代码进行回复将确保服务器不会自动退出您(ping 超时)

最后,您应该等待,直到您登录(您会知道,因为在发送 JOIN / PRIVMSG / 其他命令之前您将收到原始数字 001)。

PING :7091A8FB

This is the issue preventing you from registering on the IRC Server.

While you should (technically) be able to register on IRC with a NICK / USER combination, the PING you're receiving on logon is a very simple DoS protection mechanism employed by most IRC servers these days.

You need to reply to a ping as follows:

PONG :7091A8FB

The string should change every single time you receive the PING.
You will also get PING requests later to make sure the connection is still alive, so writing the code to reply will ensure that the server doesn't automatically QUIT you (ping timeout)

Lastly, you should be waiting until you have logged on (you'll know because you will receive the raw numeric 001) before you send JOIN / PRIVMSG / other commands.

悲念泪 2024-10-20 18:10:54

这可能是你的客户的问题。你可以仔细检查一下
通过使用 telnet 连接到服务器并发出类似于以下的命令
这个:(

NICK aaron
USER aaron ignored ignored :Aaron
PONG <number>

发出“NICK”命令后,您应该从
有号码的客户;这是您应该替换的数字
“”上面。)

应该将您与服务器连接起来,并且您应该收到
MOTD 和其他连接消息紧随其后。从这里开始,你
可以尝试“JOIN #test-channel”并确保您可以加入频道。
假设所有这些都按照我的描述进行,您的问题可能是
与您的 IRC 客户端。

 sec@irc:~/simple-irc-bot$ telnet 192.168.1.100 6667
 Trying 192.168.1.100...
 Connected to 192.168.1.100.
 Escape character is '^]'.
 NOTICE AUTH :*** Looking up your hostname
 NOTICE AUTH :*** Checking Ident
 NOTICE AUTH :*** Couldn't look up your hostname
 NICK TENOTICE AUTH :*** No ident response
 NICK testtest002
 PING :2153560274
 :loal.irc-server.com 461 TNICK USER :Not enough parameters
 USER test test 0 :sec
 PONG :2153560274
 :loal.irc-server.com 001 TNICK :Welcome IRC Network,
 :loal.irc-server.com 002 TNICK :Your host is loal.irc-server.com, running version u2.10.12.14

请在USER命令后面尝试PONG:2153560274

This is probably a problem with your client. You can double-check this
by connecting to the server with telnet and issue commands similar to
this:

NICK aaron
USER aaron ignored ignored :Aaron
PONG <number>

(After issuing the 'NICK' command, you should get a 'PING' from the
client with a number; this is the number you should substitute for
"" above.)

This should connect you with the server, and you should receive the
MOTD and other connect messages immediately after this. From here, you
can try "JOIN #test-channel" and ensure that you can join channels.
Assuming all of this works as I have described, your problem is likely
with your IRC client.

 sec@irc:~/simple-irc-bot$ telnet 192.168.1.100 6667
 Trying 192.168.1.100...
 Connected to 192.168.1.100.
 Escape character is '^]'.
 NOTICE AUTH :*** Looking up your hostname
 NOTICE AUTH :*** Checking Ident
 NOTICE AUTH :*** Couldn't look up your hostname
 NICK TENOTICE AUTH :*** No ident response
 NICK testtest002
 PING :2153560274
 :loal.irc-server.com 461 TNICK USER :Not enough parameters
 USER test test 0 :sec
 PONG :2153560274
 :loal.irc-server.com 001 TNICK :Welcome IRC Network,
 :loal.irc-server.com 002 TNICK :Your host is loal.irc-server.com, running version u2.10.12.14

Please try PONG :2153560274 behind USER command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文