python1003无标题_选择.错误10038,在windows上使用Python2.7编写的套接字

在Linux上运行正常的Python 2.7加密IRC客户端在Windows上遇到错误:选择.错误10038。此错误表明在非套接字对象上执行了操作。代码中使用了select.select进行套接字通信,但在Windows上不适用。文章展示了客户端的源代码,并寻求解决方案。
摘要由CSDN通过智能技术生成

因此,我用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')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值