-
-
Save ashnur/46c0fbecceb7002a514e8c3c6f88ae78 to your computer and use it in GitHub Desktop.
Windows equivalent of netstat -tulpn
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 | |
# Normally windows doesn't give out the process name when you run netstat -ano, thus making it | |
# hard to figure out what process is bound to the different ports. This script extracts the PID | |
# from the netstat output, and fetches the corresponding binary name from the tasklist, and | |
# merges the two together. Needs a MinGW environment like Git Bash and python to work. | |
{ tasklist | tail -n +5; echo ===; netstat -ano | grep LIST; } | python -c " | |
import sys | |
pad = [0, 21, 9, 0, 5, 8, 0] | |
lines = [line.strip() for line in sys.stdin] | |
sep = lines.index('===') | |
pids, listeners = lines[:sep], lines[sep+1:] | |
pid_map = {s.split()[1]: [s.split()[2], s.split()[0]] for s in pids} | |
list_map = {s.split()[4]: s.split() for s in listeners} | |
print('\n'.join(str(' '.join(val.ljust(pad[i]) for i, val in enumerate(v + pid_map[k]))) for k, v in list_map.items()))" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment