Commit e54acd9d authored by Petr Špaček's avatar Petr Špaček

scripts: make scripts/ compatible with Python 2 and Python 3

It is 2017 already, so Python 3 is the default.
parent c3de747a
#!/usr/bin/env python
#!/usr/bin/env python3
Print IP address to binary representation in Python hex format \x12
from socket import inet_pton,AF_INET6,AF_INET
from socket import inet_pton, AF_INET6, AF_INET
import sys
from binascii import hexlify
from string import find
if find(sys.argv[1], ":") == -1:
addr_type = AF_INET
addr_type = AF_INET6
x = hexlify(inet_pton(addr_type, sys.argv[1]))
arg = sys.argv[1]
sys.exit('Usage: <IPv4 or IPv6 address>')
out = ""
for i in range(0, len(x) / 2):
out += "\\x" + x[i*2] + x[i*2+1]
if ':' in arg:
addr_type = AF_INET6
addr_type = AF_INET
print out
print(repr(inet_pton(addr_type, arg)).strip("'"))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment