本文整理汇总了Python中nattraverso.ipdiscover.get_local_ip函数的典型用法代码示例。如果您正苦于以下问题:Python get_local_ip函数的具体用法?Python get_local_ip怎么用?Python get_local_ip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_local_ip函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upnp_thread
def upnp_thread():
while True:
try:
is_lan, lan_ip = yield ipdiscover.get_local_ip()
if not is_lan:
continue
pm = yield portmapper.get_port_mapper()
yield pm._upnp.add_port_mapping(lan_ip, args.net.P2P_PORT, args.net.P2P_PORT, 'p2pool', 'TCP')
except:
if p2pool_init.DEBUG:
log.err()
yield deferral.sleep(random.expovariate(1/120))
示例2: upnp_thread
def upnp_thread():
while True:
try:
is_lan, lan_ip = yield ipdiscover.get_local_ip()
if is_lan:
pm = yield portmapper.get_port_mapper()
yield pm._upnp.add_port_mapping(lan_ip, args.p2pool_port, args.p2pool_port, 'p2pool', 'TCP')
except defer.TimeoutError:
pass
except:
if p2pool.DEBUG:
log.err(None, 'UPnP error:')
yield deferral.sleep(random.expovariate(1/120))
示例3: map
def map(self, port):
"""
See interface
"""
self._check_valid_port(port)
#Port is already mapped
if port in self._mapped:
return defer.succeed(self._mapped[port])
#Trigger a new mapping creation, first fetch local ip.
result = ipdiscover.get_local_ip()
self._mapped[port] = result
return result.addCallback(self._map_got_local_ip, port)
示例4: get_external_ip
(local_ok, local_result), (external_ok, external_result) = result
if local_ok:
print 'Result of get_local_ip', local_result
local, ip = local_result
if local:
print "\tLAN IP address:", ip
else:
print "\tWAN IP address:", ip
else:
print 'Failed to get_local_ip', local_result
if external_ok:
print 'Result of get_external_ip', external_result
wan, ip = external_result
if wan == None:
print "\tLocalhost IP address:", ip
elif not wan:
print "\tLAN IP address:", ip
else:
print "\tWAN IP address:", ip
else:
print 'Failed to get_external_ip', external_result
list = defer.DeferredList([get_local_ip(), get_external_ip()])
list.addCallback(got_local_ip).addBoth(lambda x:reactor.stop())
print 'Attempting to use get_local_ip() and get_external_ip()'
reactor.run()