Skip to content

Instantly share code, notes, and snippets.

@Tony3-sec
Created July 20, 2016 16:25
Show Gist options
  • Select an option

  • Save Tony3-sec/e2255acf11da13234514d0559645c916 to your computer and use it in GitHub Desktop.

Select an option

Save Tony3-sec/e2255acf11da13234514d0559645c916 to your computer and use it in GitHub Desktop.
import sys
## Convert hexadecimal to IP address
if len(sys.argv) < 2:
print('Please type hexadecimal')
else:
i = 0
j = 2
ipaddr = ''
data = sys.argv[1]
while len(data[i:j]) != 0:
hex_data = data[i:j] #pick two chars from arg
octet = '0x' + str(hex_data)
ipaddr += str(int(octet, 16)) + str('.')
i += 2
j += 2
print(ipaddr.rstrip('.')) #strip last dot and print the IP address
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment