Sponsored Content
Top Forums Shell Programming and Scripting Convert IP address (within a line) to hostname Post 302398734 by scolazz on Thursday 25th of February 2010 12:04:01 PM
Old 02-25-2010
Convert IP address (within a line) to hostname

I have a tricky problem, and I'm quite the scripting newb.

I have Cisco ACLs that have IP addresses in them. I'd like to convert the IP's to hostnames for easier analysis. A sample ACL input file would be (I've obfuscated the IPs):

Code:
access-list acl-secure-out line 1 extended permit icmp any any 
access-list acl-secure-out line 2 extended permit tcp host 200.00.000.000 object-group ser-secure-bed eq 2049 
access-list acl-secure-out line 2 extended permit tcp host 200.00.000.000 host 10.0.000.1 eq 2049

Here is the trick - I only want to convert host IPs - so, any IP that follows the word 'host' in the ACL (which I have as a text file).

So far, I've used awk to try something like this:

Code:
awk '$8 ~ /host/ && $10 ~ /host/ {print $0, system ("dig +short -x"$9)system("dig +short -x"$11)}'

but that gives me strange output:

Code:
xxxx.xx.xxx.net.
xxxx.xx.yyyy.com.
00ess-list acl-secure-out line 2 extended permit tcp host 200.00.000.000 host 10.0.000.0 eq 2049

For some reason, the system command output prints out before the whole line, and munges up the line output (see '00ess-list' at the beginning of the 3rd line). I know that command wouldn't do exactly what I wanted, but I think I'm close.

The system command is working OK - it's looking up the hostname just fine, I just need to find a way to do that, and replace the IP in the line with the hostname, but only when the IP is preceded by the word 'host'.

I really hope I'm making sense here Smilie Any thoughts?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert ip address to ip number

I want to make a script to read a list of ip addresses from a file then convert those ip addresses to ip number. ip number is made by removing the dots then transfer to a number , so the ip number transfered to binary then to decimal which will represents the ip number 0 : 4294967295 Also I... (17 Replies)
Discussion started by: moutaz1983
17 Replies

2. UNIX for Dummies Questions & Answers

IP address/hostname problem

I have a problem that when I am pinging with the IP address it is giving me whether a server is alive or not but when I am trying it with hostname it is giving unknown host I have checked in /etc/hosts file and the IP address and hostname are both there...still the problem is there.. Can... (1 Reply)
Discussion started by: uLearner
1 Replies

3. Shell Programming and Scripting

Read Hostname and Return IP Address

Dear Experts, I have a text file on my itanium box which contains list of nearly 1000 hostnames. I do not have the IP Address of them. I want read each entry from the text file and want to do a nslookup to the DNS Server and get the IP Adresses and put them in another file in the format... (1 Reply)
Discussion started by: PrasannaKS
1 Replies

4. Shell Programming and Scripting

bash: convert mac address to 16 character format

Hi there Im not quite sure how i can do this, but i am retrieving the mac address from boxes, which in some instances is arriving in its shortened format (i.e. dropping the leading zeros)... for example 0:3:BA:1:E:84 Im trying to figure out a way of converting the single character... (3 Replies)
Discussion started by: rethink
3 Replies

5. UNIX for Dummies Questions & Answers

Routing or Iptables connections by hostname or ip address

edit; I found a solution that works, see thread #3 https://www.unix.com/302417065-post3.html Hi there, I have a small dedicated server that has four ip addresses and by default my httpd sends request using the servers main ip for all outbound connections. I'm quite amateur at routing and... (4 Replies)
Discussion started by: mooofa
4 Replies

6. Emergency UNIX and Linux Support

HP UX - ILO Console hostname different than Machine Hostname...

Hi All, So we added a new HP-UX 11.31 machine. Copied OS via Ignite-UX (DVD)over from this machine called machine_a. It was supposed to be named machine_c. And it is when you log in...however when I'm in the ILO console before logging in, it says: It should say: What gives? And how do... (4 Replies)
Discussion started by: zixzix01
4 Replies

7. UNIX for Dummies Questions & Answers

Solaris - How to get IP Address from a hostname?

We are using Solaris as our database OS. Can you please help me to know how can i get the IP address of a solaris machine in my network from its hostname? e.g. We have a remote database server with the hostname as xyz. Without connecting to the database OS, can i get the IP address of xyz OS from... (1 Reply)
Discussion started by: Anmol Sharma
1 Replies

8. AIX

AIX How to exchange hostname and IP address between two AIX servers?

Hi all, I am trying to exchange hostname and IP address of two AIX machines. But i am confused as how to change it ? do i need to use "smitty mktcpip" or "smitty tcpip" ? what is the difference between smitty mktcpip and smitty tcpip ? Also anymore steps to follow or just updating... (3 Replies)
Discussion started by: lramsb4u
3 Replies

9. AIX

Mutt from address and hostname

Mutt 1.2.3.1i AIX 5.3.12.1 We need to send email to external addresses. But are having problems with the sent-from hostname. They're going out with @server.mycompany.com. We need them to be @mycompany.com. I'm setting from and hostname with -e 'set from="From... (1 Reply)
Discussion started by: Papa Lee
1 Replies

10. Solaris

SMTP relay one (1) hostname with two (2) IP Address

Hi, Anyone can help? Currently : I'm am using a smtp smart relay, 1 hostname but different IP Address 192.168.2.108 and 192.168.2.109). I'm using "smtp.mailhostname.com mailhost" and having an IP Address 192.168.2.108, but there is a certain minutes/seconds that the IP Address will... (2 Replies)
Discussion started by: fspalero
2 Replies
ASP(1)								    User Manual 							    ASP(1)

NAME
asp - find an host IP address by its name SYNOPSIS
asp [-uv] [-f | [-d dir] [-e ext]] [-a addresses] [-r repetitions] [-s send_delay] [-w wait_time] [-p port] hostname asp -V DESCRIPTION
Asp finds the IP address of an Internet connected host. In order to find it, the peer hostname (not the FQDN), and the range of its possi- ble IP addresses need to be specified. Those IP addresses could be simple IP addresses as 127.0.0.1 or "metaip" addresses as 127.0.0.1-20 or 127.0.0.*: the former is a simple way to avoid to type a lot of consecutive addresses, the latter is short for 127.0.0.1-254. In order to simplify the management of the associations between hostnames and addresses, asp searches in a specified directory a text file containing the possible IP addresses of the looked for host. The name of the text file has to be formed by the hostname followed by an optional extension of your choice. For example to find the author's dynamic IP address, obviously if I am on line, you can provide my metaip address on standard input with the command: echo "195.31.186.1-62 194.166.58.2-18" | asp -f atomic or you can put my metaip address in a file called atomic in your ~/.asp directory, like this: echo "195.31.186.1-62 194.166.58.2-18" > ~/.asp/atomic and then you can simply do: asp atomic OPTIONS
-u Update the file /etc/hosts with the IP address of hostname or delete the possible old entry if the address is not found. Obviously the file have to by writable by the user. -v Include more verbiage to make output readable by humans. Default consists only of dotted quad IP address, which is intended for output substitution in scripts. -f Force the reading of addresses from standard input instead that from the hostname's file. -d dir Set the directory containing the addresses file referred by hostname to dir. Default is ~/.asp. -e ext Set addresses files extension to ext. Default is no extension. -a addresses Set the number of queries to send before make a pause of send_delay seconds. Default is 12 queries. -r repetitions Set the number of times to try the same address. Default is 3 times. -s send_delay Delay the sending of the next group of addresses send_delay seconds. Default is 2 seconds. -w wait_time Wait the peer reply for wait_time seconds. Default is 5 seconds. -p port Specify an alternative port number. For default the port number is obtained searching the asp entry in /etc/services. -V Show version information. ENVIRONMENT
ASPCMD This variable could be used to store your preferred settings. An option set in this environment variable could be overridden or tog- gled from command line. BUGS
UDP is an unreliable protocol, therefore there is a chance you will not find the host even if it is on line. Anyway, if you are sure that the peer is on line and asp aware, you could adjust the various parameters until you get a reply. At last you will find the correct set- tings for your particular needs. This until the RDM communication style will be implemented under Linux. Obviously the hostname has to be unique among the possible IP addresses: asp will hook to the first correct reply. AUTHOR
Stenio Brunetta <stenio@brunettaeperin.it> Comments and suggestions are welcome. ACKNOWLEDGMENTS
Steven N. Hirsch <shirsch@ibm.net> for v1.3 bug fix and for the verbose option. Colin Phipps <cphipps@doomworld.com> for the tmpnam security issue. SEE ALSO
aspd(8). Linux February 1997 ASP(1)
All times are GMT -4. The time now is 09:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy