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.
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 7:07:36 AM
perl.beginners 29317 articles. 3 followers. Follow

1 Replies
405 Views

Similar Articles

[PageSpeed] 54

<overkill@sadsix.com> asked:
> I need to convert the first column of a list of IP numbers to=20
> IP addresses.  I created an array of my list but am stumped=20
> on how to convert the numbers.

#!/usr/bin/perl

use strict;
use warnings;
use Socket;

sub number_to_ip {

  return( inet_ntoa( pack( 'N', $_[0] ) ) );
}

while( <DATA> ){
  my( $number, $hostname ) =3D split;
  print $hostname . " =3D> " . number_to_ip( $number ) . "\n";
}

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


HTH,
Thomas
0
t
2/20/2006 8:05:30 AM
Reply:

Similar Artilces:

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...

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...

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...

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...

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 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...

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 :...

Catch IP Address of Local Machine Insted of Server IP Address where the application is deployed at
Hai ,  I have a survey that will be sent to all the users across a group, This survey application is deployed on webserver and that link will be sent to all the group members.Right now it was capturing the IP  Address of server for all members in group , insted i need each members Local machine IP Address to be sent the database via server.  I tried using the following two requests but all they are doing is capturing the server ip address:  String clientName = Request.ServerVariables["LOGON_USER"]; String clientName = Request.ServerVariables["REMOTE_ADD...

Gwia, "Bind exclusively to TCP/IP Address" and Secondary IP addresses problem...
Hello, I have a GWIA on a Bordermanger server with 3 private nics and 1 public. Gwia works with a groupwise PO server but also relays as an SMTP server other applications (like Topcall, Hp management server notifications, Listmessenger server etc.). Relays occur on different IP addresses on the different nics... By default, gwia listen and works with all the IP addresses and bordermanger filters have been configured accordingly. On the public side, the ptr dns record matches a secondary ip address. But, because of that, I get more and more errors like the following: &q...

Allow duplicate ip address command didn't work in Master IP Address Resource
Hiya. I have a 3 node nw6.5 sp3 cluster. The node with the Master ip address was poison pilled and the master ip address went to another server, however in the logger of the server it went to it shows the duplicate IP address message TCPIP-6.59-185: Sun Aug 14 23:38:25 2005 Added secondary IP address 139.143.51.2. TCPIP-6.59-344: Sun Aug 14 23:38:25 2005 WARNING : Duplicate IP address in use. Contact your system administrator. The Load script for the master ip address resource hasn't been changed and it does have the lines ignore_error set allow ip address duplicates...

How to display All IP Addresses of a particular IP segment?
I am in a intra network where i have to display all the IP addresses that are falling under our network segment.Say, we team of 10 members are under IP segment 111.222.333.* likeuser-1: 111.222.333.101user-2: 111.222.333.121user-3: 111.222.333.65user-4: 111.222.333.167user-5: 111.222.333.43user-6: 111.222.333.69user-7: 111.222.333.103user-8: 111.222.333.124user-9: 111.222.333.85user-10:111.222.333.99So, i need to fetch all ip addresses assigned under that segment and display all these 10 ip addresses.I have code where if i provide IPAddress value, it can return Hostname, and vice versa.but h...

How to get private ip address (intranet IP)
I found some webs at thailand taht can trace both the internet ip and the private ip address, (if user using intranet), of user who are interacting with web site. For Asp.NET . Are there some way to get a private ip address of user ? The link to web site that can traces private ip address http://www.pantip.com/tech/developer/topic/DN1701518/DN1701518.html ...

How do I add an 'IP Address' field to my SQL Database and code the Confirm.aspx.vb page to write IP addresses to it?
I use Storefront Software 6.6 for my E-commerce site and would like to know:How to add an 'IP Address' field to my SQL Database and code the Confirm.aspx.vb page of my website to write IP addresses to it? Specific instructions would be appreciated. Many thanks.Steve Piotrow, All Things Arctic...

Web resources about - IP Number/ IP Address Array - 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, ...

Barack Obama outlines counter-terrorism plans in rare Oval Office address; vows to 'destroy' Islamic ...
US president Barack Obama brands Islamic State fighters thugs and killers in a rare address to the nation in the wake of last week's California ...

The backwards notion that Obama was late for the glamorous 2015 Kennedy Center Honors because he needed ...
Here's the standard presentation of that notion in People Magazine , replete with video, from which I grabbed this still. But I think the address ...

Figure out how to address your cover letter - Business Insider Deutschland
... a specific individual. Just because a job posting omits the name of the person in charge of the hiring process doesn't mean you should address ...

Obama speaks on ISIS, gun control, tolerance in Oval Office address - Videos - CBS News
... shows terrorism is now in a new phase. He promised to destroy anyone who tries to harm Americans. It was the president’s first address from ...

Obama's address sets stage for 2016
Obama's address guarantees terrorism and Muslim relations will be central to the '16 campaign, Politico's Ben White says.

President Obama's Address: 'Freedom Is More Powerful Than Fear'
Here is the full text of his speech, as provided by the White House. Tonight, I addressed the nation from the Oval Office on my top priority ...

In weekly address, Obama asks Americans to 'stay true to who we are' in fight against terrorism
x YouTube Video This week, like last week, President Obama devoted his weekly address to the fight against terrorism. As I said in my speech ...

Obama’s Sunday Address Watched By 46 Million Viewers
... Obama 's Sunday night primetime speech might have, according to GOP White House candidates, been too little too late – and why give the address ...

Women Must Address Tyranny Of "Bitch" Culture
For a highly evolved society so intrigued by and invested in progress, it's funny how the "bitch" word demeaning women since as early as the ...

Resources last updated: 12/13/2015 3:15:19 AM