Translate

Image of Modern Operating Systems (3rd Edition)
Image of XSLT 2.0 and XPath 2.0 Programmer's Reference (Programmer to Programmer)
Image of Advanced Programming in the UNIX Environment, Second Edition (Addison-Wesley Professional Computing Series)
Image of RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302) (Certification Press)

Using Perl Net::IP to Manipulate IPv4 Addresses

In a previous post, I demonstrated a Korn shell script which determined the subnet mask for a range of IPv4 addresses. Perl has a module called Net::IP which provides a number of functions which can be used to manipulate IPv4 (and also IPv6) addresses to provide the same information and a lot more besides. For example, the following code outputs a lot of information about a classless prefix: use Net::IP; my $ip = new Net::IP (‘10.1.1.0/24’) or die (Net::IP::Error()); print ("IP : ".$ip->ip()."n"); print ("Sho : ".$ip->short()."n"); print ("Bin : ".$ip->binip()."n"); print ("Int : ".$ip->intip()."n"); print ("Mask: ".$ip->mask()."n"); print ("Last:

Calculate IPv4 Subnet Mask and Prefix

Here is a simple ksh93 script which I recently wrote to calculate the subnet mask and prefix when given a range of IPv4 addresses. It makes use of the bit manipulation facilities available in ksh93. #!/bin/ksh93 [[ $# != 2 ]] && { echo "Usage: $0 ipaddress1 ipaddress2" exit 1 } SaveIFS=$IFS IFS="./" typeset -a IParr1=($1) typeset -a IParr2=($2) IFS=$SaveIFS typeset -i2 ip11=${IParr1[0]} typeset -i2 ip12=${IParr1[1]} typeset -i2 ip13=${IParr1[2]} typeset -i2 ip14=${IParr1[3]} typeset -i2 ip21=${IParr2[0]} typeset -i2 ip22=${IParr2[1]} typeset -i2 ip23=${IParr2[2]} typeset -i2 ip24=${IParr2[3]} mask=0; match=1 for ((arr=1; arr < 5; arr++)) do binary_value1="" binary_value2="" for ((b=7; b >= 0;

Spoof an IPv4 ARP Response

This post demonstrates how to spoof the response to an ARP request and thus poison the ARP cache of the requesting computer.