Filter out IP addresses in domain resolve script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filter out IP addresses in domain resolve script
# 1  
Old 03-16-2012
Filter out IP addresses in domain resolve script

Hello everyone,

I have written a one liner which looks in a configuration file for remote hosts to connect to. It then resolves them by first ping, and nslookup if it fails, then places the info in the hosts file.

The whole thing works, seemingly, apart from one slight issue. I would like to filter out remote hosts which are already specified as IP addresses, since it is obviously unnecessary to resolve them. I am learning sed slowly, but can anyone help achieve this?

Here is the script currently
Code:
cat connect.conf | grep "remote " | awk '{print $2}' | cut -d : -f1 | sort | uniq | while read SRV ; do if ! grep $SRV /etc/hosts ; then IP=$(ping -c 1 $
SRV | grep "64 bytes from " | awk '{print $4}' | cut -d : -f1) ; if [ $IP == "" ] ; then IP=$(nslookup host $SRV | grep Server: | awk '{print $2}') ; fi ; if [ $IP != "" ] ; then echo $IP 
$SRV >> /tmp/hosts; fi ; fi ; done

I think that this following sed command is useful for placing after uniq or after the first cut command, however I believe it needs altered

Code:
sed 's/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}//'

Can anyone assist in this? Any help would be appreciated!

Edit: Fixed it, silly me Smilie
Code:
grep -Ev '([0-9]{1,3}\.){3}[0-9]{1,3}'


Last edited by haggismn; 03-16-2012 at 09:12 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script getting IP's and MAC addresses

Hy over there, Lets make it simple :) Using a bash script, how to grep only the ip address and the mac address and put them in a file:. for example from the dhcp.conf file we got such things: The script will end up with two columns IP's and MAC adresses as it is showed below: ... (9 Replies)
Discussion started by: hermouche
9 Replies

2. Shell Programming and Scripting

How and What should I read/study to can resolve this script?

Hello everyone, I am a newbie on the world Shell Script. I just can build some scripts basically with the command which I used on the terminal. With the part algorithmic I don't have problem, but some functionality I can't and didn't know how around the situation. I have the file .txt with... (5 Replies)
Discussion started by: enodev
5 Replies

3. UNIX for Dummies Questions & Answers

Get domain names from IP addresses of apache2 access.log

I am totally new to shell scripting. I want to see people from which domain access my website. I want to generate the domain names from IP addresses in the Apache access.log file. There are around 54 log files. I concatenate all the files into one. I am using Ubuntu 12.04 LTS. So I... (4 Replies)
Discussion started by: Ronni
4 Replies

4. UNIX for Dummies Questions & Answers

Script to ftp in to multiple ip addresses

Hello Is there an easy way to login to various ip's..one after the other. I need to login to about 30 aix boxes and put a file in each one... Cheers (1 Reply)
Discussion started by: Grueben
1 Replies

5. Windows & DOS: Issues & Discussions

Script to ftp in to multiple ip addresses

Hello Is there an easy way to login to various ip's..one after the other. I need to login to about 30 aix boxes and put a file in each one... Cheers (1 Reply)
Discussion started by: Grueben
1 Replies

6. Shell Programming and Scripting

Please help to resolve the below script

Dear Members, Please help me to resolve below script. The script is used to send the attachment in the mail with all the details. However in one of the incidents, the attachment in the mail was blank. Now the client is after me to get it resolved ASAP. So prompt response would be highly... (2 Replies)
Discussion started by: SKO_TC
2 Replies

7. Shell Programming and Scripting

script to get all ip addresses of servers into a file

Hi all i need to create a script that pings every server in my range (0-254) adn then returns the values to a file? can anyone please help. i am working in the tcsh ( and yes i know how to ping ) but i dont know how to ping them all in one script without copying and pasting a 254 times? ... (1 Reply)
Discussion started by: brian112
1 Replies

8. Shell Programming and Scripting

Help with bash script to block IP addresses

I am using a bash script for CentOS 5.5, I found one and modified it, however I want to block the incoming IP addresses and ALLOW the IP addresses that are blocked to send out email. I will use an internal network range for an example, 10.10.10.0/24 (if a lot of spam is incoming) from this range... (0 Replies)
Discussion started by: grifs71
0 Replies

9. Shell Programming and Scripting

How can i send mail to multiple addresses in same domain in bash?

Suppose i have a txt file that is the list of the addresses,something like: lala0045 john james lala0234 george james and i want to send an email to lala0045@blabla.com and lala0234@blabla.com,the same domain...what is the exact syntax i should use in my script? there is a command... (10 Replies)
Discussion started by: bashuser2
10 Replies

10. Shell Programming and Scripting

Script to get IP addresses of LAN computers

I need a shell script for OS X, one that can find IP addresses of machines connected to my LAN, get the names of the computer associated with those addresses, then display them like so in a list: "Bob's L33T Boxx: #.#.#.#" Something like the network scanner in Apple Remote Desktop is what I'm... (1 Reply)
Discussion started by: sladuuch
1 Replies
Login or Register to Ask a Question