Have you ever googled a port number to figure out what service uses it? I think every system administrator must have done this. But how to approach when there are a lot of port numbers to search?
So, I thought giving it a try with PowerShell, to programmatical get port information of lots of port numbers.
The Idea and Making it work:
- First get information for all the ports, but where to get it? I read somewhere during my engineering graduation days, that port numbers are assigned by IANA (Internet Assigned Numbers Authority). How about checking their website first.So I found a link on IANA’s website which has port numbers in a CSV format and downloaded the file.
- Once you have the information, filter out all unnecessary things and store them in a CSV or JSON format, so that it can be easily uploaded/downloaded from a Public Github gist.Using the below script I filtered out the required information and pasted/committed it to my Github repository , from where it could be downloaded to any machine since it is Public.
- Write a Powershell function that can
- Web request above mentioned public Github gist URL and downloads the content.
- Filter out port number you’re trying to search from the content, and display the results
Following is the PowerShell function to get above done
- Make sure when the Powershell function runs for the first time, it creates a local copy of content in a File at a static location, which could be accessed to get port information locally for all Future function calls by avoiding the Web request which is slower.Took care of point-6 in my PowerShell function like in the screenshot below
Running the Function:
You can run the function on demand like in the below screenshot.
Please Note – The First call to the function would be slow, but from the next call you have a local copy of the CSV file on your machine, which can be queried comparatively much faster to web requests.
Hope you’ll find the script useful and Thanks for reading, Cheers! 🙂