Introduction:
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? Is there a port checker for that?
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 port checker 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! 🙂
My new book : PowerShell Scripting Guide to Python
This PowerShell Scripting guide to Python is designed to make readers familiar with syntax, semantics and core concepts of Python language, in an approach that readers can totally relate with the concepts of PowerShell already in their arsenal, to learn Python fast and effectively, such that it sticks with readers for longer time.
“Use what you know to learn what you don’t. ” also known as Associative learning.
Book follows a comparative method to jump start readers journey in Python, but who is the target audience? and who should read this book –
- Any System Administrator who want to step into Development or Programming roles, and even if you don’t want to be a developer, knowledge of another scripting language will make your skill set more robust.
- Python Developers who want to learn PowerShell scripting and understand its ease of user and importance to manage any platform.
Python is one of the top programming languages and in fast changing IT scenarios to DevOps and Cloudto the future – Data Science, Artificial Intelligence (AI) and Machine Learning Python is a must know.
But this PowerShell Scripting guide to Python would be very helpful for you if you already have some knowledge of PowerShell
NOTE! This is a Leanpub “Agile-published” book. That means the book is currently unfinished and in-progress. As I continue to complete the chapters, we will re-publish the book with the new and updated content. Readers will receive an email once a new version is published!
While the book is in progress, please review it and send any feedback or error corrections at prateek@ridicurious.com
Prateek Singh
Related posts
9 Comments
Leave a Reply to ilufdmkfy@gmail.comCancel reply
Categories
Author of Books
Awards
Open Sourced Projects
Author at
Blog Roll
Mike F RobbinsDamien Van Robaeys
Stéphane van Gulick
Kevin Marquette
Adam Bertram
Stephanos Constantinou
Francois-Xavier Cat
Ravikanth Chaganti
Roman Levchenko
Blog Stats
- 1,132,764 People Reached
Just wanted to point out that the ‘port’ variable is marked as mandatory, but there is no helpmessage for it.
Fixed that, Thanks for pointing out. Cheers!
Also noticed a typo in your port validaterange code. Should be 65535.
Otherwise, cool function.
You are a saviour! 🙂
[…] on May 8, 2017 submitted by /u/Prateeksingh1590 [link] [comments] Leave a […]
Thank you for sharing superb informations. Your web-site is fantastically cool. I am impressed by the details that you have proceeding this web site. It reveals how nicely you perceive this subject. Bookmarked this web call, will be as long as backside in support of more articles. You, my friend, ROCK! I originate simply the info I previously searched all more than the place and just couldn’t extend athwart. Could you repeat that? an ideal trap site.
You have brought up a very superb points , appreciate it for the post.
[…] Query Port Information using Powershell […]
[…] Query Port Information using Powershell […]