Created
November 21, 2018 05:06
-
-
Save orimanabu/1e2f15152ee2ecebc902909b9fce0ff2 to your computer and use it in GitHub Desktop.
Decode sin_addr.s_addr in Python
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
#!/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