0 Replies - 1268 Views - Last Post: 02 September 2009 - 12:45 PM

#1 syfran  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 83
  • View blog
  • Posts: 1,103
  • Joined: 12-July 09

Retreive the complete list of Ports

Posted 02 September 2009 - 12:45 PM

Description: make the program executable and simply run with no arguments.Download and extract the complete list of ports ( official and unofficial ) from Wikipedia
#!/bin/bash                                                 
# Gets Port List from Wikipedia, includes both official and unofficial ports
# Saves as ports.lst and backsup the previous list                          

#Variables
DLFILE="htmlPortList"
DLURL="http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers"
OFILE="ports.lst"                                                    

# checks if the file exists, if it does back it up
if [ -e $OFILE ]; then                            
        mv $OFILE ${OFILE}.bak                    
fi                                                

# get the file
# remove space after w
w get -q -O $DLFILE $DLURL

# sed commands to edit the file

# get the middle of the list
# then delete the last two lines that were just extra crap
# remove all current newlines
# remove all of the rows and replace them with newlines
# remove all the columns and replace them with tabs
# remove the rest of the html tags

sed  -n '/^<td>0*/TCP,UDP*/,/<p><a name="Dynamic/p' $DLFILE 
| sed 'N;$!P;$!D;$d'
| sed -e :a -e '$!N;s/n//;ta'
| sed 's/<tr[^>]*>/nn/g'
| sed 's/<td[^>]*>/t/g'
| sed 's/<[^>]*>//g' >  $OFILE
rm $DLFILE



Is This A Good Question/Topic? 0
  • +

Page 1 of 1