1

我运行这个网站,并且我批准了该网站的一部分供人们访问。我只想批准静态ip。如果我有一堆 IP,我如何确定它们是否是静态的?我可以做剩下的部分,但套接字库中可能有一些功能,或者可以让我编写该部分的脚本以查找用户使用的是静态 IP 还是动态 IP。

谢谢 !

Php/Js 也可以。

4

3 回答 3

3

There is no way to inherently tell if an IP address is static or dynamically assigned. Based on the hostname that the IPs resolve to, you could probably make a guess as to whether they are static or not, but there is nothing definitive to facilitate this.

You could use the socket module to resolve the IPs to hostnames and flag them as "static" or "dynamic" based on some kind of "best guess" algorithm, but it would be only that: a best guess.

Here is an example using a random Verizon FiOS IP address. This assumes that any IP starting with "pool" is dynamically assigned.

>>> hostname = socket.gethostbyaddr('71.243.222.111')[0]
>>> if 'pool' in hostname: 
...     print hostname, 'is dynamic'
... 
pool-71-243-222-111.lsanca.fios.verizon.net is dynamic

You're going to have a very tough time determining all of the various naming conventions and this would in no way be a complete solution.

You might want to ask yourself what kind of problem you're trying to solve first, and whether filtering access by IP address is providing the kind of verification you need.

于 2011-04-18T21:01:21.087 回答
0

我会使用一个务实的解决方案:新帐户有几天的试用期。之后,他们只能从用于注册的同一 IP 登录。如果它们仍然具有相同的 IP,则很可能是静态的。

于 2011-04-18T21:25:41.713 回答
0

嗯,你没有问题,是吗?如果他们要求从 IP X 访问,你就给他们从 IP X 访问。如果事实证明它是动态的并且他们切换,他们就不再有访问权限。实际上,无法从动态 IP 访问 :)

不过说真的,IP 分配类型的权限是用户正在访问的主机。因此,您需要询问用户它在他/她的配置中所说的内容。

于 2011-04-18T21:25:49.983 回答