Convert IPs to decimal and back

This is a simple script that interactively converts an IP address to its decimal equivalent. This can sometimes be used to bypass web content filtering devices as not all will convert the decimal to an IP and then a hostname.

#!/usr/bin/perl
 #
 # prompt for an IP
 print "Enter an IP Address: ";
# get the users input
 $_ = ;
# remove the newline "n" character
 chomp($_);
# should validate the input, but this was a simple/quick program
 $converteddecimal = ip2dec($_);
 $convertedip = dec2ip($converteddecimal);
print "nIP address: $_n";
 print "Decimal: $converteddecimaln";
# print "IP: $convertedipn";
# this sub converts a decimal IP to a dotted IP
 sub dec2ip ($) {
 join '.', unpack 'C4', pack 'N', shift;
 }
# this sub converts a dotted IP to a decimal IP
 sub ip2dec ($) {
 unpack N => pack CCCC => split /./ => shift;
 }

Tags

Related Posts

Share This

Add extra IPs to a server

1. Determine what existing range files exist:

# cd /etc/sysconfig/network-scripts/

# ls ifcfg-eth1-range*

You will see at least one file, possibly several. Find the highest number following the “range” and add one to it. This will be the new range number.

For example, if you see ifcfg-eth1-range0 and ifcfg-eth1-range1, your new range number will be “3”.

2. Determine the next available interface number (clone number).

# ifconfig | grep eth1

You will see a list of interfaces that looks like this

eth1 Link encap:Ethernet HWaddr 00:08:74:A3:29:70
eth1:0 Link encap:Ethernet HWaddr 00:08:74:A3:29:70
eth1:1 Link encap:Ethernet HWaddr 00:08:74:A3:29:70
.
.
.
eth1:8 Link encap:Ethernet HWaddr 00:08:74:A3:29:70

Find the highest number after the “eth1:”. Add one to it and this your new clone number. In this case it would be 9.

3. create a range file for the new range number. (for this example, we will use range3)

# vi ifcfg-eth1-range3

4. Write the following lines to the range file. (replace the dummy ip information with your desired ip range and the CLONENUM_START value with the one calculated above)

IPADDR_START='123.0.0.1'
IPADDR_END='123.0.0.10'
CLONENUM_START='9'

5. Write and quit the range file, and restart your network.

# /etc/init.d/network restart

6. Your new ips should now be visible by running:

# ifconfig

 

Tags

Related Posts

Share This