Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- os.system("cls||clear") # Clear the terminal screen
- stream = os.popen("netstat -lnt | grep tcp | awk '{ print ( $4 ) }' | awk 'BEGIN{FS=\":\"} { print $(NF) }' | sort -n | uniq") # Get all open TCP ports
- result = stream.read()
- stream = os.popen("netstat -lnu | grep udp | awk '{ print ( $4 ) }' | awk 'BEGIN{FS=\":\"} { print $(NF) }' | sort -n | uniq") # Get all open UDP ports
- result += stream.read()
- result = result.split("\n") # Convert the result into a list
- result = " ".join(result).split() # Remove empty elements, if there are any
- result.sort() # Sorts the list alphabetically ascending
- print(result)
Add Comment
Please, Sign In to add comment