#!/usr/bin/perl # # make /etc/services file from IANA web site. # © TiChou use strict; my $url = "http://www.iana.org/assignments/port-numbers"; my $ver = "1.0"; my $date = "2003/01/27"; use POSIX qw(strftime); open(IANA,"lynx -dump -dont_wrap_pre $url|") || die "Can't connect to www.iana.org : $!\n"; print "# /etc/services, version $ver $date TiChou # # See \"man 5 services\" for more information. # # The Internet network services list (updated ".(strftime "%Y/%m/%d", localtime).") # # Port numbers are assigned by the IANA (Internet Assigned Numbers Authority), # and their current policy is to assign both TCP and UDP protocols when # assigning a port number. Therefore, most entries will have two entries, even # for TCP only services. # # The latest IANA port assignments can be found on : # # $url # # The port numbers are divided into three ranges : # # - The Well Known Ports are those from 0 through 1023, # - The Registered Ports are those from 1024 through 49151, # - The Dynamic and/or Private Ports are those from 49152 through 65535. # ################################################################################ # WELL KNOWN PORT NUMBERS # # The Well Known Ports are assigned by the IANA and on most systems can only be # used by system (or root) processes or by programs executed by privileged # users. # # service-name port/protocol aliases comments "; my ($port); while () { s/\s+$//; if (/^(|#|[^\s#]+)\s+(\d+)(|-\d+|\/(tcp|udp|sctp))(\s+(#\s+)?(.*))?$/) { if ($2 == 1024 && $4 eq "tcp") { print "################################################################################ # REGISTERED PORT NUMBERS # # The Registered Ports are listed by the IANA and on most systems can be used by # ordinary user processes or programs executed by ordinary users. # # service-name port/protocol aliases comments "; } print $1; print "\t"x(2-int(length($1)/8)); print " "x(8-(int(length($1)/16)*length($1))%16-length($2)); print "$2$3"; print "\t\t\t# $7" if ($7); print "\n"; } elsif (/^([^\s#]+)\s+(\d+)-(\d+)\/tcp(\s+(#\s+)?(.*))?$/) { for $port ($2..$3) { print $1; print "\t"x(2-int(length($1)/8)); print " "x(8-(int(length($1)/16)*length($1))%16-length($port)); print "$port/tcp"; print "\t\t\t# $6" if ($6); print "\n"; print $1; print "\t"x(2-int(length($1)/8)); print " "x(8-(int(length($1)/16)*length($1))%16-length($port)); print "$port/udp"; print "\t\t\t# $6" if ($6); print "\n"; } } } print "################################################################################ # DYNAMIC AND/OR PRIVATE PORTS # # service-name port/protocol aliases comments # End of /etc/services. "; close(IANA);