Skip to main content

List open ports and listening services

netstat

To list open network ports and the processes that own them on FreeBSD with netstat,
you can use this command:

  netstat -a | egrep 'Proto|LISTEN'
The output for this on my laptop running FreeBSD is:

Proto Recv-Q Send-Q  Local Address      Foreign Address    (state)
tcp4       0      0  localhost.ipp      *.*                LISTEN


tcp6       0      0  localhost.ipp      *.*                LISTEN


tcp4       0      0  *.2200             *.*                LISTEN


tcp6       0      0  *.2200             *.*                LISTEN


tcp4       0      0  *.x11              *.*                LISTEN


tcp6       0      0  *.x11              *.*                LISTEN


The localhost.ipp entry refers to the Internet Printing Protocol, used by CUPS to talk to the network printer.
 The *.2200 entry refers to SSH, which I have set to a nonstandard port -- so it's not recognized by netstat's
 port-to-service association capabilities. *.x11, meanwhile, refers to the X Window System protocol.

You can add the -n option to netstat to get port numbers instead of having the utility try to provide names for services:

  netstat -an | egrep 'Proto|LISTEN'
The output would then look somewhat different:

Proto Recv-Q Send-Q  Local Address      Foreign Address    (state)
tcp4       0      0  127.0.0.1.631      *.*                LISTEN


tcp6       0      0  ::1.631            *.*                LISTEN


tcp4       0      0  *.2200             *.*                LISTEN


tcp6       0      0  *.2200             *.*                LISTEN


tcp4       0      0  *.6000             *.*                LISTEN


tcp6       0      0  *.6000             *.*                LISTEN


This information can be used to determine what services are running, in cases where services are using standard ports.
On a FreeBSD system, you can get a listing of standard port associations by searching through the contents of /etc/services.
 For instance, if you wanted to find out what was up with port 631, you might use this command:

  grep -w 631 /etc/services
The output:

ipp     631/tcp    #IPP (Internet Printing Protocol)
ipp     631/udp    #IPP (Internet Printing Protocol)


sockstat

In addition to netstat, the more limited command sockstat is effectively tailor-made for this kind of information gathering.
 To get a listing of listening ports and their associated processes, you can use this command:

  sockstat -4l
The output may even be more useful than that of netstat above:

USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
root     cupsd      1701  4  tcp4   127.0.0.1:631         *:*


root     cupsd      1701  6  udp4   *:631                 *:*


root     sshd       1685  4  tcp4   *:2200                *:*


root     Xorg       1154  3  tcp4   *:6000                *:*


root     syslogd    907   7  udp4   *:514                 *:*


Linux distributions

As with FreeBSD, the obvious choice of tool to use for listing open ports is netstat. Most Linux distributions use a
 different version of the utility, however -- maintained separately from the Linux distribution, as an independent software
 development project.

One consequence of that fact is that the command line options used to achieve the same results may be different with FreeBSD
 than with Debian, Ubuntu, or Fedora Core Linux systems. On a typical Linux system, this command will list open network ports
 and the processes that own them:

  netstat -lnptu
The output should look something like this:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address   Foreign Address  State   PID/Program name


tcp        0      0 127.0.0.1:631   0.0.0.0:*        LISTEN  2458/cupsd


tcp        0      0 127.0.0.1:5432  0.0.0.0:*        LISTEN  2353/postgres


tcp6       0      0 :::22           :::*             LISTEN  2335/sshd


udp        0      0 0.0.0.0:631     0.0.0.0:*                2458/cupsd


As you can see from this output, the Debian GNU/Linux system on which I ran that command has only four open ports -- two for CUPS,
 so that the computer can communicate with the network printer; one for PostgreSQL so that it can be contacted by applications in
 development; SSH, so that I can access it remotely, from my laptop.

Microsoft Windows XP

Microsoft Windows also offers a netstat command that can be executed from the command line to get a list of open ports.
 The standard MS Windows version of netstat is slightly more limited than its Unix-like system counterparts, but still suffices to
 get a listing of listening services:

  netstat -a | find "LISTENING"
The output of this command should look something like this:

TCP    hostname:epmap           hostname:0               LISTENING
TCP    hostname:microsoft-ds    hostname:0               LISTENING


TCP    hostname:10110           hostname:0               LISTENING


TCP    hostname:netbios-ssn     hostname:0               LISTENING


. . . with "hostname" replaced by the system's hostname, of course.

Commercial UNIX Systems

For most commercial UNIX systems, even if there is not a version of netstat or sockstat available, you should be able to
 install lsof -- which is short for "list open files". Most Linux distributions and BSD Unix systems will provide lsof with
 a default install or through their respective software management systems. Some commercial UNIX systems do so as well,
and for many others you can download it. The following command will limit the output of the utility to network ports:

  lsof -i -n | egrep 'COMMAND|LISTEN'
The output should look something like this (as run on my laptop, again):

COMMAND   PID USER   FD   TYPE     DEVICE SIZE/OFF NODE NAME
Xorg     1154 root    1u  IPv6 0xc6042000      0t0  TCP *:x11 (LISTEN)


Xorg     1154 root    3u  IPv4 0xc6041cb0      0t0  TCP *:x11 (LISTEN)


sshd     1685 root    3u  IPv6 0xc6041ae0      0t0  TCP *:2200 (LISTEN)


sshd     1685 root    4u  IPv4 0xc6041910      0t0  TCP *:2200 (LISTEN)


cupsd    1701 root    3u  IPv6 0xc6041740      0t0  TCP [::1]:ipp (LISTEN)


cupsd    1701 root    4u  IPv4 0xc6041570      0t0  TCP 127.0.0.1:ipp (LISTEN)

Comments

Popular posts from this blog

ESP32-C6 Wi-Fi Logger with Browser GPS + Heat Map Dashboard

This project is an ESP-IDF firmware for the Seeed Studio XIAO ESP32-C6 that turns the board into a self-hosted, secure Wi-Fi scanning logger. It creates its own access point, serves a responsive HTTPS web UI, logs nearby Wi-Fi access points, optionally tags rows with GPS coordinates (provided by the client browser), and exposes battery status from the on-board LiPo input. The end result is a pocket Wi-Fi “survey” tool: scan, track, export logs as CSV, and generate a heat map view to visualize RSSI vs location. Project overview and feature set: :contentReference[oaicite:1]{index=1} What it does AP + Station mode so the device can serve the dashboard while scanning nearby Wi-Fi networks. HTTPS web interface using a bundled certificate/key for local secure access. Single scan and continuous tracking modes. CSV export for analysis and archiving. Persistent logging to SPIFFS at /spiffs/logs.csv . Battery monitoring via ADC with voltage/percentage/status sh...

learn how to sniff wireless passwords with pirni

The thing about the iPod Touch and the iPhone is that they are great portable hacking devices. To the naked eye the iPod Touch/iPhone looks like nothing more than an ordinary mp3 player/cellphone however that is just an understatement to its full potential. Once your Ipod Touch/iPhone is jailbroken you have access to your whole file system meaning that applications generally associated with laptop/desktop hacking can be ported and used on the iPod Touch/iPhone. This opens up a whole lot of possibilities for network sniffing, port scanning and much much more! In this tutorial we are going to take a look at one of these programs called Pirni. What is Pirni? Pirni is an application that was ported to The Ipod Touch/iPhone to be used as a native network sniffer. Pirni is so useful because it gets past the iPod Touch’s/iPhone’s wifi hardware limitation of not being able to be set into promiscious mode (a mode that allows a network device to intercept and read each network packet that arrive...

how to run a GUI application throw SSH using X11

soo all we need is first to install the ssh server on the server - machine we like to control so - 1. sudo su 2. apt-get install openssh-server . . now back to our machine using the ssh : 1. ssh -V -X username@the-server-ip 2. enter the password and that is it now we can run any GUI application that install on the server using his CPU cycles yahhhh great !! for example lets run WireShark : 3. gksudo wireshark & now all that if we runing tow Linux machines !! but what windows users that like to run a linux app??! !! soo we need it tow applications 1. putty you can get it here : http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html 2.Xming you can get it here : http://sourceforge.net/projects/xming/ ok so first we need to install Xming , and after that we going to use butty but we need to cheak Enable X11 forwarding in connection -- > SSH -- > X11 >> Enable x11 forwarding . and that is it free to run any linux application on windows using SSH . have fun ...