Python IRC 机器人无法加入
我收到错误消息
: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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为有两个可能的原因:
I see two possible reasons for that:
我注意到您不处理 PING 请求,有些服务器在您回复 PING 请求之前不接受任何其他命令(因此未注册)。
您需要连接,然后是 NICK,检查 PING,然后是 USER,如果 USER 之前没有 PING,则再次检查 PING。
有些服务器喜欢在 NICK 之后发送,其他服务器则在 USER 之后发送。
要响应此 PING,只需发送:
在
:
和'\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.
To respond to this PING, simply send:
Between the
:
and'\r\n
will be a random string that you need to send back with your PONG as shown above.发送“USER ...”和“JOIN ...”之间的时间需要增加。我在 Bash 中执行相同代码时遇到了这个问题。我是这样做的:
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:
这是阻止您在 IRC 服务器上注册的问题。
虽然您(从技术上讲)应该能够使用 NICK/USER 组合在 IRC 上注册,但您在登录时收到的 PING 是当今大多数 IRC 服务器所采用的非常简单的 DoS 保护机制。
您需要按如下方式回复 ping:
每次收到 PING 时,该字符串都应该更改。
稍后您还会收到 PING 请求以确保连接仍然有效,因此编写代码进行回复将确保服务器不会自动退出您(ping 超时)
最后,您应该等待,直到您登录(您会知道,因为在发送 JOIN / PRIVMSG / 其他命令之前您将收到原始数字 001)。
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:
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.
这可能是你的客户的问题。你可以仔细检查一下
通过使用 telnet 连接到服务器并发出类似于以下的命令
这个:(
发出“NICK”命令后,您应该从
有号码的客户;这是您应该替换的数字
“”上面。)
这应该将您与服务器连接起来,并且您应该收到
MOTD 和其他连接消息紧随其后。从这里开始,你
可以尝试“JOIN #test-channel”并确保您可以加入频道。
假设所有这些都按照我的描述进行,您的问题可能是
与您的 IRC 客户端。
请在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:
(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.
Please try PONG :2153560274 behind USER command.