Created
August 15, 2015 06:58
-
-
Save marhar/eea1a4d5c43da81b5a26 to your computer and use it in GitHub Desktop.
Python: is this address a multicast address?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ismulticast(hostname): | |
"""is this address a multicast address?""" | |
# -- yes if bits 0-3 are 1110 | |
import socket | |
import struct | |
ip=socket.gethostbyname(hostname) | |
mreq=struct.pack("4sl",socket.inet_aton(ip),socket.INADDR_ANY) | |
return ord(mreq[0]) & 0xf0 == 0xe0 | |
for i in ('localhost','138.72.131.168','239.239.239.7','10.1.1.1'): | |
print ismulticast(i),i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment