Header Banner
Null Byte Logo
Null Byte
wonderhowto.mark.png
Cyber Weapons Lab Forum Metasploit Basics Facebook Hacks Password Cracking Top Wi-Fi Adapters Wi-Fi Hacking Linux Basics Mr. Robot Hacks Hack Like a Pro Forensics Recon Social Engineering Networking Basics Antivirus Evasion Spy Tactics MitM Advice from a Hacker

How to Easily Find What Port a Service Runs On and Vice-Versa

May 29, 2015 12:04 AM
May 30, 2015 03:34 PM
"How to Easily Find What Port a Service Runs On and Vice-Versa" cover image

I wrote a python script that allows you to easily ask what service runs on a specific port and vice-versa. Now, I am sure that such a program already exists on our lovely linux OS's, but... I didn't think of that before I started, and haven't found it yet. So if you haven't found it yet either, maybe you'll find this of some use.

Terminal output showing the usage and error message for the `getpart` command in a command-line interface.

It's just called getport. If I have a port number, and want to know what services run on that port, I do:

getport 1234 (or whatever number)

System information displaying Microsoft SQL Server details.

and if I have the name of a service, or a keyword (sql, oracle, ssh etc.) I can do:

getport mysql

OR

getport ssh etc..

If there is no match for your search, the script simply does nothing..

How to Easily Find What Port a Service Runs On and Vice-Versa
Command line output showing active network services and their ports.
How to Easily Find What Port a Service Runs On and Vice-Versa
Command line output showing active network services and their ports.

Get the script:

You can get it here:

http://pastebin.com/q5Ae0gRj

When you get it you'll need to make it executable like this:

go to the directory it's in

cd ~/directory/of/script (wherever it is)

make it executable

sudo chmod +x getport

And preferably put it somewhere on your system PATH so you can call it from anywhere.

And ready to go. Thanks for reading!

Extra stuff - What it's doing:

It's basically just looking for your port/service/keyword, in the file /etc/unicornscan/ports.txt which is on my kali linux by default, and I assume is also on yours.. thus I have hardcoded that path into the script. If you don't have it though, or if you want this to work on other linux OS's, there is a file: /etc/services which looks very similar to the unicorn one, except seemlingly far more established on linux systems, seeing as it has it's own manpage(you want man services...). However, I preferred the layout of the ports.txt for this, but the script could easily be changed to use /etc/services instead.

You already know how to use your phone. With Gadget Hacks' newsletter, we'll show you how to master it. Each week, we explore features, hidden tools, and advanced settings that give you more control over iOS and Android than most users even know exists.

Sign up for Gadget Hacks Weekly and start unlocking your phone's full potential.

Related Articles

Comments

No Comments Exist

Be the first, drop a comment!