因此,我用python 2.7编写了一个简单的加密IRC客户端。在linux上,它可以正常工作,但是在windows上,我得到了以下错误:选择.错误:(10038,“试图对不是套接字的对象执行操作”)。
我做了一些研究,我知道在windows上我不能这样选择,但是作为一个新手,我没有足够的知识去获得它工作。所以我的代码是:import socket
import os
import sys
import select
from Crypto.Cipher import ARC4
import base64
if(len(sys.argv) < 3) :
print 'Usage : python ./joczoirc.py hostname port nickname room(without the # !!!) enc_password'
sys.exit()
server = sys.argv[1]
port = int(sys.argv[2])
botnick = sys.argv[3]
room = sys.argv[4]
enckey = sys.argv[5]
channel = '#' + room
def encrypt(key, plaintext):
cipher = ARC4.new(key)
return base64.b64encode(cipher.encrypt(plaintext))
def decrypt(key, ciphertext):
cipher = ARC4.new(key)
return cipher.decrypt(base64.b64decode(ciphertext))
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #definialjuk a socketot
print "connecting to:"+server
irc.connect((server, port)) #kapcsolodas a szerverhez
irc.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :Joczo Encrypted IRC\n") #user authentication
irc.send("NICK "+ botnick +"\n") #sets nick
irc.send("PRIVMSG nickserv :iNOOPE\r\n") #auth
irc.send("JOIN "+ channel +"\n") #join the chan
while 1:
socket_list = [1, irc]
read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])
for sock in read_sockets:
if sock == irc:
text=irc.recv(2040)
if text.find('PING') != -1: #ha talal 'PING' szot
irc.send('PONG ' + text.split() [1] + '\r\n') #viszakuldi 'PONG' szot szervernek hogy meg online van
if text.find(':') != -1:
before_privmsg, privmsg, after_privmsg = text.partition('PRIVMSG')
print '[+] ' + before_privmsg
before_uzenet, uzenet, after_uzenet = text.partition(channel+' :')
if text.find('TITKOS') != -1:
before_encedmsg, encedmsg, after_encedmsg = text.partition('TITKOS')
demsg = decrypt(enckey,after_encedmsg)
print '[-] ' + demsg
else:
print '[!] ' + after_uzenet
else:
mymsg = sys.stdin.readline()
encmsg = encrypt(enckey,mymsg)
irc.send('PRIVMSG '+channel+' : TITKOS'+encmsg+'\r\n')