IP Number/ IP Address Array #2

Greetings,

I need to convert the first column of a list of IP numbers to IP 
addresses.  I created an array of my list but am stumped on how to convert 
the numbers.

File:
180884576       imstrmcs05
180884577       imstrmcs06
180884578       imstrmcs07
180884579       imstrmcs08
180884580       imstrmcs09
180884581       imstrmcs10


Script:
# Properly formatting into an array
open(IPLIST, "file") || die "couldn't open the file";

while ($x = <IPLIST>)
{
chop $x;
@arr = split /\s+/,$x;
print "@arr\n";
}

# Converting IP number to IP address.
foreach $ipaddr {
$ip1 = int ($ipaddr / (256**3));
$ipaddr %= ($ip1 * 256**3);
$ip2 = int ($ipaddr / (256**2));
$ipaddr %= ($ip2 * 256**2);
$ip3 = int ($ipaddr /256);
$ip4 = $ipaddr % ($ip3 * 256);

$realip=$ip1 . "." . $ip2 . "." . $ip3 . "." . $ip4;
print "$realip\n";
}

close(IPLIST);

0
overkill
2/20/2006 6:11:19 AM
perl.beginners 29317 articles. 3 followers. Follow

1 Replies
404 Views

Similar Articles

[PageSpeed] 57

overkill@sadiqs.net wrote:
> Greetings,

Hello,

> I need to convert the first column of a list of IP numbers to IP
> addresses.  I created an array of my list but am stumped on how to
> convert the numbers.
> 
> File:
> 180884576       imstrmcs05
> 180884577       imstrmcs06
> 180884578       imstrmcs07
> 180884579       imstrmcs08
> 180884580       imstrmcs09
> 180884581       imstrmcs10
> 
> 
> Script:
> # Properly formatting into an array
> open(IPLIST, "file") || die "couldn't open the file";
> 
> while ($x = <IPLIST>)
> {
> chop $x;
> @arr = split /\s+/,$x;
> print "@arr\n";
> }
> 
> # Converting IP number to IP address.
> foreach $ipaddr {
> $ip1 = int ($ipaddr / (256**3));
> $ipaddr %= ($ip1 * 256**3);
> $ip2 = int ($ipaddr / (256**2));
> $ipaddr %= ($ip2 * 256**2);
> $ip3 = int ($ipaddr /256);
> $ip4 = $ipaddr % ($ip3 * 256);
> 
> $realip=$ip1 . "." . $ip2 . "." . $ip3 . "." . $ip4;
> print "$realip\n";
> }
> 
> close(IPLIST);

Use the Socket module:

john@d154-20-234-189:~> echo "180884576       imstrmcs05
180884577       imstrmcs06
180884578       imstrmcs07
180884579       imstrmcs08
180884580       imstrmcs09
180884581       imstrmcs10" | perl -le'
use Socket;
while ( <> ) {
    my @arr = split;
    my $ip = inet_aton $arr[ 0 ];
    print inet_ntoa $ip if defined $ip;
    }
'
10.200.20.96
10.200.20.97
10.200.20.98
10.200.20.99
10.200.20.100
10.200.20.101




John
-- 
use Perl;
program
fulfillment
0
krahnj
2/20/2006 8:36:44 AM
Reply:

Similar Artilces:

IP Number/ IP Address Array
I need to convert the first column of a list of IP numbers to IP addresses. I created an array of my list but am stumped on how to convert the numbers. File: 180884576 imstrmcs05 180884577 imstrmcs06 180884578 imstrmcs07 180884579 imstrmcs08 180884580 imstrmcs09 180884581 imstrmcs10 Script: # Properly formatting into an array open(IPLIST, "file") || die "couldn't open the file"; while ($x = <IPLIST>) { chop $x; @arr = split /\s+/,$x; print "@arr\n"; } # Converting IP number to IP address...

Problem the IP address showing is NOT my IP address I am at.
host217-35-99-250.in-addr.btopenworld.com or 217.35.99.250 is someone else's IP address, not my IP address (12.98.80.XXX a Dynamic IP address range) when I test my ports with the NanoProbe system. In message <b6i8f8$tp1$1@news.grc.com>, abcministoragellc <abcministoragellc@netzero.net> kicked in with > >host217-35-99-250.in-addr.btopenworld.com >or 217.35.99.250 >is someone else's IP address, not my IP address (12.98.80.XXX a Dynamic >IP address range) >when I test my ports with the NanoProbe system. Had the same here, a couple of minute...

What is Ip address if network card has more than one ip address assigned
Okay, I have a machine running sqlanywhere server, I have several ip addresses bound to the network card. if I am going to use a client on another computer, what ip address is sqlanywhere server bound to? Regards, Andy Pick one! Then when you configure the db server us it: -x TCPIP{MYIP=xxx.xxx.xxx.xxx} -- Jim Egan [TeamPS] Dynamic Data Solutions, Inc. http://www.dyn-data.com Houston, TX *********************************************************** Enterprise Applications in Your Future? JumpStart '99 Ent...

Unauthorized source IP address (ip was: 10.8.254.250), Connot connect my app 2 facebook
Hi there,  It has been a while that i'm trying 2 connect my c# asp.net app to facekook, but without success. I always get the same Error message: Unauthorized source IP address (ip was: 10.8.254.250), and the "Source error" always mark that part in the code: Line 38:         else if (!String.IsNullOrEmpty(authToken))Line 39:         {Line 40:             fbService.CreateSession(authToken); // <--Line 41:  ...

POA shows old ip address for client/server ip address
i just upgraded groupwise from 5.5 to 6.5 Clients cannot access via tcp/ip even though its setup with the correct ip address in console one. when looking at the poa log file at the server, it gives the old server ip address instead of the current ip address. I cannot find that old ip address in any settings, or is there another problem that is keeping me from accessing via the client using tcp/ip. Hi, Have you checked the POA startup file? Settings in there for the ipaddress and port override anything put into consoleone. Cheers, Steve <bfish@emily.ne...

Imanager 2.5 on OES Linux change IP address or Port number?
--____JEXPQPPCSVXBHMYYIMTJ____ Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; modification-date="Wed, 9 May 2006 12:32:40 +0100" Hi, Can anyone tell me how I can change the port number or ip address for = imanager 2.5 on OES Linux SP2? I am also running ifolder 3.2 on port 443 (webaccess aswell) and I want = imanager to be on a different port or ip address. I am quite new to linux = apache. thanks in advance. steve. --____JEXPQPPCSVXBHMYYIMTJ____ Content-Type: multipart/related; boundar...

Changing to NAT using Private IP address What to do with OLd IP addresses
I have a client that is setting up NAT and using private addresses for the internal network. If we add new IP addresses to DCHP, do we delete the old addresses or is there a way to specify which set of Ip addresses for DHCP to hand out? Also, is there a way to just edit the present addresses? We looked and we are not able to see a way to edit the addreses. Thanks in advance for your help and advice. PLW In article <KVn8c.8445$jb5.1118@prv-forum2.provo.novell.com>, wrote: > If we add new IP addresses to DCHP, do we delete the > old addresses or is there a wa...

IP Blacklist
I just got this message when trying to get on IRC: Your IP address xxx.xxx.xxx.xxx is listed in dnsbl.dronebl.org I think this is a blacklist that IRC servers use to keep spammers or problem clients off their networks. I just got this this morning. The IP address given to me by my ISP is a 10.x.x.x address. That is, I'm behind a NAT router that is run by my ISP. My point is, another pain of not having a public IP is that if anyone of your ISP's clients decides to do something that gets them blacklisted from most IRC servers, you also get to enjoy being blacklisted :...

IP and IPX to Just IP #2
Hi, I am new to Netware and have the following question: If this is not the fourm for this please advise. I have a Netware 5.1 sp7 server. I want to only use only IP and not IPX when the client connects. The problem I am having is that the server IP address is 12.x.x.x and the workstation addresses are in the 10.x.x.x range. When I install the client on these machines and choose only IP I cannot seem to connect to the server. Without changing the Server IP to the 10.x.x.x range what needs to be done for this to work. Your help is really appreciated. Thanks, Marty ...

2 IP for postfix with IP alias
Hi, I am working for a company which needs to send mass-mailing to its thousands of customers (newsletter). For now, we send mails from only one IP xx.xx.xx.xx and we wish to separate mails between 2 IP: one IP (xx.xx.xx.xx) reserved for mass-mailing and another IP (yy.yy.yy.yy) for other mails. We have only one mail server running with Postfix. The server have 1 network interface card eth3 with IP 10.0.0.5, so I was thinking about using IP aliasing to add another IP to this interface (IP 10.0.0.7) in order to connect to the server by both IP. The problem is that when we access...

IP Addressing question
It seems to me that this is an elementary TCP-IP networking question. I must have skipped class for a baseball game that day <g>. I have two networks connected via VPN (watchguard) at two offices: Pittsburgh: 192.168.1.0/24 Cleveland: 192.168.2.0/24 We can communicate over the tunnel between the two networks without problem. However, what I want to do now is to set up a new computer for the branch (2.x) network, but I want to do it *here* in the Pittsburgh network (1.x). Unfortunately, it doesn't work. If I give the server an IP addres...

How to force MTA to use cluster ip address rather than physical ip address
Hi, Is there a way to force the MTA to use the virtual ip address for outbound connection. We run GW 6.5 SP2 in cluster with 6 nodes. We want to add an external Domain who have to go through a firewall. We added a rule to let the virtual ip address of the MTA to pass but we see that the MTA are using the physical ip address of the server so if the resource migrate, MTA will use an other address and my rule will not work anymore until I add the 6 physical ip address of each node, thing I don't want to do. Regards, Eric Bellavance Ministere des Finances It should...

IP address #2
Hello,=20 I have a requirement to get the IP address of a user logged from a = remote machine on to UNIX machine. Now the user can be using multiple = logins through VPN or otherwise. I need to create something akin to = command "finger" which will return the user his IP address based on his = current session.=20 Can someone point me in the right direction of how to do it?? Thanks=20 Shishir On Friday, June 7, 2002, at 09:41 , Shishir K. Singh wrote: > I have a requirement to get the IP address of a user logged from a remote > machine on to UNIX mach...

ip address #2
Hi I would like to make a page that shows an ip address , anyone know how to do this ?arnt we all happy this forum does not take pics for sigs ;) You mean the IP of the client that is calling the page? Then try this: <% Response.Write(Request.ServerVariables("REMOTE_ADDR")) %> Does this help?Bart De Smet [MVP] Visit www.msdn.be, www.bartdesmet.net <% Response.Write(Request.ServerVariables("REMOTE_ADDR")) %> Dim hostName As String = Request.UserHostAddress Label1.Text = hostName does the same ?arnt we all happy this forum does...

Web resources about - IP Number/ IP Address Array #2 - perl.beginners

File:Ipv6 address.svg - Wikipedia, the free encyclopedia
I, the copyright holder of this work, release this work into the public domain . This applies worldwide. This file contains additional information, ...

Lies and More Lies: Another Look at Obama's State of the Union Address
Lies and More Lies I commented on Obama's state of the union address in Brilliant Bullshit! Let's check out an alternative viewpoint. In the ...

Here's everything Facebook is doing this year to address its 'pathetic' diversity numbers
... So therefore you're less likely to be the people graduating with degrees and with the skills we need to hire. We're using TechPrep to address ...

At D.C. meeting, Emanuel does little to address Laquan McDonald controversy
Chicago Tribune At D.C. meeting, Emanuel does little to address Laquan McDonald controversy Chicago Tribune Mayor Rahm Emanuel speaks at the ...

In Flint and beyond, people come together to address city's water crisis
Christian Science Monitor In Flint and beyond, people come together to address city's water crisis Christian Science Monitor As the crisis ...

Cuomo Talks $15 Minimum Wage During State Address
'Millions of low-wage workers have to choose between paying taxes and buying food'

In weekly address, Obama proposes employment insurance reforms
x YouTube Video President Obama used this week’s address to push to “modernize our employment insurance system.” If a hardworking American ...

President Obama Last State of the Union Address Recap Group Group
Trump is small potatoes. Obama had his sights set on bigger things last night.

AMD quarterly results show improvement, Zen will address 80 percent of server market
AMD's Q4 2015 figures are in, and they show some small improvements compared to what we saw in Q3 of last year. We also heard a few tidbits on ...

Flint crisis clouds Snyder's State of the State address
Detroit Free Press Flint crisis clouds Snyder's State of the State address Detroit Free Press LANSING — Last year at this time, Gov. Rick ...

Resources last updated: 1/21/2016 5:43:19 PM