Created
November 27, 2023 10:45
-
-
Save sharpicx/2e8b760858ef2f0ec26d0549cbbb6243 to your computer and use it in GitHub Desktop.
converting /proc/net/tcp into readable stuff using python and shell
This file contains 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
#!/bin/bash | |
convert_ip_address() { | |
IFS=':' read -ra parts <<< "$1" | |
ip="" | |
for part in "${parts[@]:0:4}"; do | |
ip+=$(printf "%d." 0x$part) | |
done | |
ip=${ip::-1} | |
port=$(printf "%d" 0x${parts[4]}) | |
echo "$ip:$port" | |
} | |
local_address="00000000:14EB" | |
rem_address="7102010A:8BFA" | |
converted_local_address=$(convert_ip_address "$local_address") | |
converted_rem_address=$(convert_ip_address "$rem_address") | |
echo "Converted Local Address: $converted_local_address" | |
echo "Converted Remote Address: $converted_rem_address" |
This file contains 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
def convert_ip_address(ip_address): | |
parts = ip_address.split(':') | |
ip = '.'.join([str(int(part, 16)) for part in parts[:4]]) | |
port = str(int(parts[4], 16)) | |
return ip + ':' + port | |
local_address = '00000000:14EB' | |
rem_address = '7102010A:8BFA' | |
converted_local_address = convert_ip_address(local_address) | |
converted_rem_address = convert_ip_address(rem_address) | |
print("Converted Local Address:", converted_local_address) | |
print("Converted Remote Address:", converted_rem_address) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment