This is a discussion on Simple ipcalc perl script within the Shell scripting forums, part of the Development/Scripting category; Sorry for posting a perl script in Shell scripting section . Though this will be useful for sysadmins.. This is ...
|
|||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
|||
|
Sorry for posting a perl script in Shell scripting section . Though this will be useful for sysadmins..
This is a simple perl script to calculate network address and broadcast address. User should input ip and netmask. More linux tips @ unix - linux - storage ---------- Perl code: ---------- #!/usr/bin/perl # Get ipaddress and netmask from user my $ipaddr=$ARGV[0]; my $nmask=$ARGV[1]; my @addrarr=split(/\./,$ipaddr); my ( $ipaddress ) = unpack( "N", pack( "C4",@addrarr ) ); my @maskarr=split(/\./,$nmask); my ( $netmask ) = unpack( "N", pack( "C4",@maskarr ) ); # Calculate network address by logical AND operation of addr & netmask # and convert network address to IP address format my $netadd = ( $ipaddress & $netmask ); my @netarr=unpack( "C4", pack( "N",$netadd ) ); my $netaddress=join(".",@netarr); print "Network address : $netaddress \n"; # Calculate broadcase address by inverting the netmask # and do a logical or with network address my $bcast = ( $ipaddress & $netmask ) + ( ~ $netmask ); my @bcastarr=unpack( "C4", pack( "N",$bcast ) ) ; my $broadcast=join(".",@bcastarr); print "Broadcast address: $broadcast\n"; # END of program Here is the output of it. [root@unixfoo tmp]# ./ipcalc.pl 139.18.16.119 255.255.254.0 Network address : 139.18.16.0 Broadcast address: 139.18.17.255 [root@unixfoo tmp]# |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Change root password using perl script? | Raj1 | Solaris/OpenSolaris | 8 | 06-13-2008 11:01 PM |
| Perl simple html mail | chiku | Coding in General | 3 | 08-17-2007 07:59 PM |
| Quick improvements to avoid hacking to a Perl form Script | mariolima | Coding in General | 0 | 07-10-2007 06:57 PM |
| let users change password using perl script? | james bond | Getting started tutorials | 9 | 05-24-2007 10:32 PM |
| Need help writing simple copy script | z3cka | Shell scripting | 4 | 08-27-2006 02:29 PM |