带套接字的python公共ip(err:无法分配请求的地址) [英] python public ip with sockets (err:cannot assign requested addr)
问题描述
在让树莓派在python中访问路由器socketname.bind(96.231.140.202,9999)
的端口9999后,给我一个无法分配的错误
为了向前移植,我使用了:
myfiosgateway.com/#/firewall/portforward(相同的方法
在我的apache服务器上工作),我已经验证了96.231.140.202是我的发布ip
After allowing my raspberry pi to access port 9999 of my router socketname.bind(96.231.140.202,9999)
in python gives me a cannot assign error
To port forward I used:
myfiosgateway.com/#/firewall/portforward (the same method
worked fo my apache server) and I have verified that 96.231.140.202 is my pub ip
推荐答案
您无法绑定到公共IP.您的路由器正在执行此操作.相反,您想绑定到专用IP并将目的地为9999的端口转发流量转发到pi上的绑定IP,此地址将属于RFC兼容的专用IP范围,因此很可能是192.168.1.12之类的东西
You cannot bind to your public IP. Your router is doing that. You instead want to bind to your private IP and port forward traffic destined to 9999 to your bound IP on your pi, this address will fall into the rfc compliant private IP ranges, so it will most likely be something like 192.168.1.12 or something similar.
例如:
socketname.bind(0.0.0.0,9999) #the use of 0.0.0.0 will automatically find your available interface on that raspberry pi.
如果您让我确切知道您正在使用的套接字库,那么我可以编写准确的代码.
If you let me know exactly what socket library youa re using I can craft the exact code.
这篇关于带套接字的python公共ip(err:无法分配请求的地址)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!