Skip to content

Instantly share code, notes, and snippets.

@orimanabu
Created November 21, 2018 05:06
Show Gist options
  • Save orimanabu/1e2f15152ee2ecebc902909b9fce0ff2 to your computer and use it in GitHub Desktop.
Save orimanabu/1e2f15152ee2ecebc902909b9fce0ff2 to your computer and use it in GitHub Desktop.
Decode sin_addr.s_addr in Python
#!/usr/bin/python
import socket
import struct
import sys
#value = 191041708
def to_ipaddr(value):
packed = socket.ntohl(value)
x = struct.pack('!I', packed)
return socket.inet_ntoa(x)
if __name__ == '__main__':
value = int(sys.argv[1])
print(to_ipaddr(value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment