我按照名爲「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()方法 –