请求的地址在其上下文错误中无效

请求的地址在其上下文错误中无效

本文介绍了请求的地址在其上下文错误中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在学习名为Black Hat Python"的教程时遇到了请求的地址在其上下文中无效"错误.我是 Python IDE 版本:2.7.12这是我的代码:

I was following a tutorial called "Black Hat Python" and got a "the requested address is not valid in its context" error. I'm Python IDE version: 2.7.12This is my code:

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
>>>

推荐答案

您正在尝试绑定到一个实际上并未分配给您的网络接口的 IP 地址:

You are trying to bind to an IP address that is not actually assigned to your network interface:

bind_ip = "184.168.237.1"

请参阅 Windows 套接字错误代码文档:

See the Windows Sockets Error Codes documentation:

WSAEADDRNOTAVAIL 10049
无法分配请求的地址.

请求的地址在其上下文中无效.这通常是由于尝试绑定到对本地计算机无效的地址所致.

The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer.

这可能是您的路由器在使用 NAT(网络地址转换)与您的计算机通信之前侦听的 IP 地址,但这并不意味着您的计算机根本无法看到该 IP 地址.

That may be an IP address that your router is listening to before using NAT (network address translation) to talk to your computer, but that doesn't mean your computer sees that IP address at all.

绑定到 0.0.0.0,这将使用所有可用的 IP 地址(本地主机和配置的任何公共地址):

Either bind to 0.0.0.0, which will use all available IP addresses (both localhost and any public addresses configured):

bind_ip = "0.0.0.0"

或使用您的计算机配置的任何地址;在控制台中运行 ipconfig/all 以查看您的网络配置.

or use any address that your computer is configured for; run ipconfig /all in a console to see your network configuration.

您可能也不想使用端口

1024;这些是为仅作为 root 运行的进程保留的.如果您想运行非特权进程,则必须选择比该数字更高的数字(在大多数教程程序中,这正是您想要的):

You probably also don't want to use ports < 1024; those are reserved for processes running as root only. You'll have to pick a higher number than that if you want to run an unprivileged process (and in the majority of tutorials programs, that is exactly what you want):

port = 5021  # arbitrary port number higher than 1023

我相信您所关注的具体教程使用了 BIND_IP = '0.0.0.0'BIND_PORT = 9090.

I believe the specific tutorial you are following uses BIND_IP = '0.0.0.0' and BIND_PORT = 9090.

这篇关于请求的地址在其上下文错误中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 10:20