You are not logged in.

#1 2011-07-26 04:00:16

dodo3773
Member
Registered: 2011-03-17
Posts: 814

[SOLVED] All port numbers that can access internet in Linux

I have found a list of all available port numbers. I would like to know which ones can access the internet. I have figured out quite a few like email, web, ssh, dynamic. I am writing a script that monitors web traffic. Here is what I have so far:

#! /bin/bash
#fixed="-e .*:80 -e .*:443"
#range=$( echo "-e"\ '.*:'{444..67777} )

# Local Host
httprange=$( echo "-e" '127\.0\.*' )
ports=$( echo "$httprange" )

grepped=$( netstat --tcp --numeric | awk 'NR>2 {print $5}' | grep -w $ports | sort -n -t : -k 2,2 | uniq )

if [ "$grepped" ]; then
  echo 'Local Host'
  echo "$grepped"
  echo " " #Blank Line To Clean Up Output
fi

# Local Area Network
httprange=$( echo "-e" '192\.168\.*' )
ports=$( echo "$httprange" )

grepped=$( netstat --tcp --numeric | awk 'NR>2 {print $5}' | grep -w $ports | sort -n -t : -k 2,2 | uniq )

if [ "$grepped" ]; then
  echo LAN
  echo "$grepped"
  echo " " #Blank Line To Clean Up Output
fi


# HTTP Ports 
httprange=$( echo "-e"\ '.*:'{80,443,8080} )
ports=$( echo "$httprange" )

grepped=$( netstat --tcp --numeric | awk 'NR>2 {print $5}' | grep -w $ports | sed '/192.168.*/d' | sed '/127.0.*/d' | sort -n -t : -k 2,2 | uniq )

if [ "$grepped" ]; then
  echo Web
  echo "$grepped"
  echo " " #Blank Line To Clean Up Output
fi


# FTP Ports 
ftprange=$( echo "-e"\ '.*:'{20,21,47,69,115,152,215,247,349,574,662,989,990,1758,1818,2529,2811,3305,3713,4687,5402,6619,6620,6621,6622} )
ports=$( echo "$ftprange" )

grepped=$( netstat --tcp --numeric | awk 'NR>2 {print $5}' | grep -w $ports | sed '/192.168.*/d' | sed '/127.0.*/d' | sort -n -t : -k 2,2 | uniq )

if [ "$grepped" ]; then
  echo Ftp
  echo "$grepped"
  echo " " #Blank Line To Clean Up Output
fi


#Email Ports
emailrange=$( echo "-e"\ '.*:'{25,110,143,465,585,587,993,995} )
ports=$( echo "$emailrange" )



grepped=$( netstat --tcp --numeric | awk 'NR>2 {print $5}' | grep -w $ports | sort -n -t : -k 2,2 | uniq )

if [ "$grepped" ]; then
  echo Email
  echo "$grepped"
  echo " " #Blank Line To Clean Up Output
fi




#Ports Not Yet Assigned  
unassigned=$( netstat --tcp --numeric | awk 'NR>2 {print $5}' | sed '/:25/d' | sed '/:80/d' | sed '/:110/d' | sed '/:143/d' | sed '/:443/d' | sed '/:465/d' | sed '/:585/d' | sed '/:587/d' | sed '/:993/d' | sed '/:995/d' | sed '/:8080/d' | sed '/192.168.*/d' | sed '/127\.0\.*/d' | sed '/:20/d' | sed '/:21/d' | sed '/:47/d' | sed '/:69/d' | sed '/:115/d' | sed '/:152/d' | sed '/:215/d' | sed '/:247/d' | sed '/:349/d' | sed '/:574/d' | sed '/:662/d' | sed '/:989/d' | sed '/:990/d' | sed '/:1758/d' | sed '/:1818/d' | sed '/:2529/d' | sed '/:2811/d' | sed '/:3305/d' | sed '/:3713/d' | sed '/:4687/d' | sed '/:5402/d' | sed '/:6619/d' | sed '/:6620/d' | sed '/:6621/d' | sed '/:6622/d' |sort -n -t : -k 2,2 | uniq )

if [ "$unassigned" ]; then

  echo Dynamic 
  echo "$unassigned"
fi
echo " "
exit

 

I was not sure what section to put this post in. It did not seem like a network question. Also, the code works so not a general programming question either (if anyone has any tips they are welcome though; I am interested). This script is a long time in the works. The real problem I have is that there are some low level ports I am unsure of and some ports I do not understand what they are. I use this in my conky and it has proven very useful. Here is what I used to reference the port numbers http://www.iana.org/assignments/port-numbers If anyone has a better reference with more explanation or any insight please let me know.

Last edited by dodo3773 (2011-07-26 21:56:20)

Offline

#2 2011-07-26 08:54:28

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,223
Website

Re: [SOLVED] All port numbers that can access internet in Linux

dodo3773 wrote:

I would like to know which ones can access the internet

Huh? That statement doesn't make sense.

dodo3773 wrote:

Here is what I used to reference the port numbers http://www.iana.org/assignments/port-numbers If anyone has a better reference with more explanation or any insight please let me know.

You'll find the same list in /etc/services

Offline

#3 2011-07-26 14:01:11

Zenettii
Member
From: London
Registered: 2011-06-26
Posts: 5
Website

Re: [SOLVED] All port numbers that can access internet in Linux

All port numbers can access the internet if you want them to.
If you meant what can be acessed from the internet (IE. someone connecting to your PC) you can use nc or do a port scan against your box to see whats being accepted/open.

Try "man nc" or take a look into iptables which can be really useful info (personally and professionally)


When one person suffers from a delusion, it is called insanity.
When many people suffer from a delusion it is called religion - Robert Pirsig

Offline

#4 2011-07-26 21:25:53

dodo3773
Member
Registered: 2011-03-17
Posts: 814

Re: [SOLVED] All port numbers that can access internet in Linux

fukawi2 wrote:
dodo3773 wrote:

I would like to know which ones can access the internet

Huh? That statement doesn't make sense.

dodo3773 wrote:

Here is what I used to reference the port numbers http://www.iana.org/assignments/port-numbers If anyone has a better reference with more explanation or any insight please let me know.

You'll find the same list in /etc/services

I thought that only certain ports could access the internet by default. I will look more into /etc/services.

Offline

#5 2011-07-26 21:29:58

dodo3773
Member
Registered: 2011-03-17
Posts: 814

Re: [SOLVED] All port numbers that can access internet in Linux

Zenettii wrote:

All port numbers can access the internet if you want them to.
If you meant what can be acessed from the internet (IE. someone connecting to your PC) you can use nc or do a port scan against your box to see whats being accepted/open.

Try "man nc" or take a look into iptables which can be really useful info (personally and professionally)

I will look more into it. I just thought that there was a list somewhere with more explanation on some of the port numbers. Linux specific I mean. I do not think that I completely understand the way ports work (I would like to know). I will definitely look more into iptables. There are a couple of ports on foreign hosts that I would not mind blocking permanently.

Edit: All ports being able to access the internet is what I wanted to know. I still have much to learn. Thanks. Marking thread as solved.

Last edited by dodo3773 (2011-07-26 21:55:34)

Offline

#6 2011-07-26 23:01:29

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,223
Website

Re: [SOLVED] All port numbers that can access internet in Linux

dodo3773 wrote:

I just thought that there was a list somewhere with more explanation on some of the port numbers. Linux specific I mean. I do not think that I completely understand the way ports work (I would like to know).

Ports are just numbers used by the protocol (TCP or UDP)... Think of them like floors in a building (a really tall building with 65,535 floors).

Every floor (port) is capable of being used ("access the internet"). What each floor (port) is used for depends entirely upon the occupier (program).

Just because the ground floor is usually/commonly used for the lobby, doesn't mean you couldn't use it for a coffee shop instead.
Just because port 80 is usually/commonly used for HTTP, doesn't mean you couldn't use it for FTP instead.

The IANA port assignment list is just a commonly agreed upon standard of port numbers to help make everything/everyone work well together (ie, we all agree that HTTPS is usually port 443, but there's plenty of instances of HTTPS being on other ports (such as 4443, 8443 or 4433 etc)).

Further details on how the ports are split up and assigned: http://en.wikipedia.org/wiki/List_of_TC … rt_numbers

Last edited by fukawi2 (2011-07-26 23:06:50)

Offline

#7 2011-07-27 00:00:07

dodo3773
Member
Registered: 2011-03-17
Posts: 814

Re: [SOLVED] All port numbers that can access internet in Linux

fukawi2 wrote:
dodo3773 wrote:

I just thought that there was a list somewhere with more explanation on some of the port numbers. Linux specific I mean. I do not think that I completely understand the way ports work (I would like to know).

Ports are just numbers used by the protocol (TCP or UDP)... Think of them like floors in a building (a really tall building with 65,535 floors).

Every floor (port) is capable of being used ("access the internet"). What each floor (port) is used for depends entirely upon the occupier (program).

Just because the ground floor is usually/commonly used for the lobby, doesn't mean you couldn't use it for a coffee shop instead.
Just because port 80 is usually/commonly used for HTTP, doesn't mean you couldn't use it for FTP instead.

The IANA port assignment list is just a commonly agreed upon standard of port numbers to help make everything/everyone work well together (ie, we all agree that HTTPS is usually port 443, but there's plenty of instances of HTTPS being on other ports (such as 4443, 8443 or 4433 etc)).

Further details on how the ports are split up and assigned: http://en.wikipedia.org/wiki/List_of_TC … rt_numbers

Thank you for the further explanation.

Offline

Board footer

Powered by FluxBB