Skip to content

Instantly share code, notes, and snippets.

@faisalfs10x
Created March 26, 2023 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faisalfs10x/52356016cb3fd2eb31df224b3a04f152 to your computer and use it in GitHub Desktop.
Save faisalfs10x/52356016cb3fd2eb31df224b3a04f152 to your computer and use it in GitHub Desktop.
Obfuscate IP address to decimal
#!/usr/bin/python3
# Obfuscate IP address to decimal
import sys
ip_address = sys.argv[1]
# Convert IP address, split into 4 list as a zero-padded 2-digit hex and join list with no separator.
hex_ip = ''.join(['{:02x}'.format(int(i)) for i in ip_address.split('.')])
# Convert hex_ip to int with base 16 since hexadecimal is base 16
decimal_ip = int(hex_ip, 16)
print('Original IP:', ip_address)
print('Decimal IP:', decimal_ip)
# PS C:\Users\fs10x> python.exe .\ip2dec.py 8.8.8.8
# Original IP: 8.8.8.8
# Decimal IP: 134744072
#
# PS C:\Users\fs10x> ping -n 2 134744072
#
# Pinging 8.8.8.8 with 32 bytes of data:
# Reply from 8.8.8.8: bytes=32 time=7ms TTL=116
# Reply from 8.8.8.8: bytes=32 time=7ms TTL=116
#
# Ping statistics for 8.8.8.8:
# Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),
# Approximate round trip times in milli-seconds:
# Minimum = 7ms, Maximum = 7ms, Average = 7ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment