简体   繁体   English

IP地址引用范围

[英]Referencing range of IP addresses

I am trying to specify a range of addresses that will be set every time an API is called. 我试图指定每次调用API时都会设置的地址范围。 For the example below, when api is referenced, I would like it to hosts in the range to a list, and not just one as it currently does. 对于下面的示例,当引用api时,我希望将其托管到列表范围内的主机,而不仅仅是当前的主机。

api = xmlrpclib.ServerProxy("http://user:pass@192.168.0.1:8442/")

Generating the addresses seems straightforward enough, but I am unsure how to store it so that when api is reference, it's sends to every host, eg 192.168.0.1 - 192.168.0.100 and not just one. 生成地址似乎很简单,但是我不确定如何存储它,以便在引用api时将其发送到每个主机,例如192.168.0.1-192.168.0.100,而不仅仅是一个。

for i in range(100):
    ip = "192.168.0.%d" % (i)
    print ip

I would also like to be able to specify the range, eg 192.168.0.5 - 192.168.0.50 rather then incrementing from zero. 我还希望能够指定范围,例如192.168.0.5-192.168.0.50,而不是从零开始递增。

Update: The API does not handle a list very well so the solution need to be able to parse the list. 更新: API无法很好地处理列表,因此解决方案需要能够解析列表。 Might this simply require a second for statement? 可能只需要一秒钟for发言时间?

If you want a different range: 如果您想要其他范围:

for i in range(5,51):
    ip = "192.168.0.%d" % (i)
    print ip

Not sure what you mean by setting multiple. 不确定设置多个意味着什么。 That for loop is doing that for you. for循环就是为您做的。 If you're talking about saving references of your api, you can also throw those into a list. 如果您正在谈论保存api的引用,则也可以将其放入列表中。

api = []
for i in xrange(5,51):
    ip = "192.168.0.%d" % (i)
    api.append(xmlrpclib.ServerProxy("http://user:pass@" + ip))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM