我按照名为“Black Hat Python”的教程获得“请求的地址在其上下文中无效”错误。我的Python IDE版本:2.7.12 这是我的代码:请求的地址在其上下文错误中无效
import socket
import threading
bind_ip = "184.168.237.1"
bind_port = 21
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((bind_ip,bind_port))
server.listen(5)
print "[*] Listening on %s:%d" % (bind_ip,bind_port)
def handle_client(client_socket):
request = client_socket.rev(1024)
print "[*] Recieved: %s" % request
client_socket.close()
while True:
client,addr = server.accept()
print "[*] Accepted connection from: %s:%d" % (addr[0],addr[1])
client_handler = threading.Thread(target=handle_client,args=(client,))
client_handler.start()
,这是我的错误:
Traceback (most recent call last):
File "C:/Python34/learning hacking.py", line 9, in <module>
server.bind((bind_ip,bind_port))
File "C:\Python27\lib\socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
error: [Errno 10049] The requested address is not valid in its context
>>>
检查'bind_ip'以查看它是否是使用'ifconfig'(linux)或'ipconfig'(windows)绑定的正确ip。尝试使用'''''bind_ip'绑定到任何接口。另外,请不要**使用端口21 - 它被保留用于FTP。使用从1024到49151的任意数字。 –
您的IP地址是本地还是远程?如果是远程,请使用.connect()方法 –