On Tue, Sep 15, 2009 at 01:16:06PM -0400, Scott Dial wrote: > I have to concur with the opinions above. I was very confused by the > following error: > > >>> addr = ipaddr.IPAddress("10.1.2.3/255.255.240.0") > ... > ipaddr.IPAddressIPValidationError: '98.223.189.24/255.255.240.0' is not > a valid address (hint, it's probably a network) > > Because, it *is* a address of a host on a network.
To me, 10.1.2.3/255.255.240.0 is not a host address, but specifies a network. I.e., 10.1.2.3/255.255.240.0 == 10.1.0.0/255.255.240.0 == 10.1.35.200/20. > >>> net = ipaddr.IPNetwork("10.1.2.3/255.255.240.0") > > But then, I was dumbfounded as to how I could get the gateway IP from > this IPNetwork object. Well, you can't. There is no way to determine a gateway, without querying the network topology. This is clearly outside the scope of this module. The only two known host addresses of a network are the network address (10.1.0.0 in the example you gave) and the broadcast address (10.1.15.255). > It took me a while to figure out that you can > iterate over IPNetwork instances: > > >>> gateway = net[1] > > I was then confused, because: > > >>> print(type(gateway)) > <class 'ipaddr.IPv4Address'> > > Which sorta blew my mind.. I fully expected to receive an IPNetwork back > from that operation. It is unclear to me why the network information > gets chucked by that operation. This makes perfect sense to me. An IP network consists of a list of IP addresses. Returning /32 networks seems kind of pointless to me. > I foresee having to work around that in > real applications by doing something obnoxious like: > > >>> actual_gateway = ipaddr.IPNetwork("%s/%s" % (gateway, addr.netmask)) But a gateway is not an IP address plus hostmask. A gateway is just a single IP address. What is the use of adding a hostmask to the gateway IP address or some other IP address inside the network? - Sebastian _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com