Package nattraverso :: Module ipdiscover
[show private | hide private]
[frames | no frames]

Module nattraverso.ipdiscover

Generic methods to retreive the IP address of the local machine.

TODO: Example

Version: 0.1.0

Author: Raphael Slinckx

Contact: raphael@slinckx.net

Copyright: Copyright 2005

License: LGPL

Classes
LocalNetworkMulticast Local IP discovery protocol via multicast:

Function Summary
twisted.internet.defer.Deferred get_external_ip()
Returns a deferred which will be called with a 2-uple (wan_flag, ip_address):
twisted.internet.defer.Deferred get_local_ip()
Returns a deferred which will be called with a 2-uple (lan_flag, ip_address) :
  _get_via_connected_udp(ipaddr)
Init a UDP socket ip discovery.
twisted.internet.defer.Deferred _get_via_multicast()
Init a multicast ip address discovery.
  _got_multicast_ip(ipaddr)
Called when we received the ip address via udp multicast.
  _on_local_ip(result)
Called when we got the local ip of this machine.
  _on_no_local_ip(error)
Called when we could not retreive by any mean the ip of this machine.
  _on_no_upnp_external_found(error, ipaddr)
Called when the UPnP device failed to return external address.
  _on_upnp_external_found(ipaddr)
Called when an external ip is found through UPNP.

Variable Summary
str __revision__ = '$id'

Function Details

get_external_ip()

Returns a deferred which will be called with a 2-uple (wan_flag, ip_address):
  • wan_flag:
    • True if it's a WAN address
    • False if it's a LAN address
    • None if it's a localhost (127.0.0.1) address
  • ip_address: the most accessible ip address of this machine
Returns:
A deferred called with the above defined tuple
           (type=twisted.internet.defer.Deferred)

get_local_ip()

Returns a deferred which will be called with a 2-uple (lan_flag, ip_address) :
  • lan_flag:
    • True if it's a local network (RFC1918)
    • False if it's a WAN address
  • ip_address is the actual ip address
Returns:
A deferred called with the above defined tuple
           (type=twisted.internet.defer.Deferred)

_get_via_connected_udp(ipaddr)

Init a UDP socket ip discovery. We do a dns query, and retreive our ip address from the connected udp socket.
Parameters:
ipaddr - The ip address of a dns server
           (type=a string "x.x.x.x")
Raises:
RuntimeError - When the ip is a bogus ip (0.0.0.0 or alike)

_get_via_multicast()

Init a multicast ip address discovery.
Returns:
A deferred called with the discovered ip address
           (type=twisted.internet.defer.Deferred)
Raises:
Exception - When an error occurs during the multicast engine init

_got_multicast_ip(ipaddr)

Called when we received the ip address via udp multicast.
Parameters:
ipaddr - an ip address
           (type=a string "x.x.x.x")

_on_local_ip(result)

Called when we got the local ip of this machine. If we have a WAN address, we return immediately, else we try to discover ip address through UPnP.
Parameters:
result - a tuple (lan_flag, ip_addr)
           (type=a tuple (bool, ip string))

_on_no_local_ip(error)

Called when we could not retreive by any mean the ip of this machine. We simply assume there is no connectivity, and return localhost address.

_on_no_upnp_external_found(error, ipaddr)

Called when the UPnP device failed to return external address.
Parameters:
ipaddr - The LAN ip address
           (type=an IP string "x.x.x.x")

_on_upnp_external_found(ipaddr)

Called when an external ip is found through UPNP.
Parameters:
ipaddr - The WAN ip address
           (type=an IP string "x.x.x.x")

Variable Details

__revision__

Type:
str
Value:
'$id'                                                                  

Generated by Epydoc 2.1 on Tue Aug 30 14:56:47 2005 http://epydoc.sf.net