Convert IP address string to binary in Python

Posted by pizzim13 on Stack Overflow See other posts from Stack Overflow or by pizzim13
Published on 2010-04-28T23:25:13Z Indexed on 2010/04/29 0:17 UTC
Read the original article Hit count: 785

Filed under:
|
|

As part of a larger application, I am trying to convert an IP address to binary. Purpose being to later calculate the broadcast address for Wake on LAN traffic. I am assuming that there is a much more efficient way to do this then the way I am thinking. Which is breaking up the IP address by octet, adding 0's to the beginning of each octet where necessary, converting each octet to binary, then combining the results. Should I be looking at netaddr, sockets, or something completely different?

Example: From 192.168.1.1 to 11000000.10101000.00000001.00000001

© Stack Overflow or respective owner

Related posts about python

Related posts about ip