Register
It is currently Sat Sep 20, 2014 10:03 pm

dig/nslookup script open resolvers.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 PostPosted: Mon May 23, 2011 5:34 am   

Joined: Mon May 23, 2011 4:52 am
Posts: 4
Hello all!

I am trying to create a script that checks the status of a list of open resolvers on there availability.

All the entry's that are responsive(active) needs to be redirected to a file so it can be used for another script.

(I'm a total newb to bashing, but i am going to learn it! but for now i need to get this script done a.s.a.p)

Code:
for IP in 192.*.*.* 192.*.*.*.* 192.*.*.*.* 192.*.*.*.* (etc...)
do
       echo $IP
       dig @$IP
done

if .....
then


With this output file i need to make a script that continues to run over and over. (for a hour or so..)

Can anyone help me into the right direction?

Thx in advance,

-Terrery


Top
 Profile  
 PostPosted: Mon May 23, 2011 7:53 am   

Joined: Thu Sep 16, 2010 3:57 am
Posts: 11
try something like this

#!/usr/local/bin/bash

IP='av.com';
while [ "2" > "1" ];
do
echo $IP
dig @$IP
sleep 1
done


Top
 Profile  
 PostPosted: Mon May 23, 2011 9:24 am   

Joined: Mon May 23, 2011 4:52 am
Posts: 4
Ok thats working :)

I am using

Code:
IP='130.*.*.*'
while :
do
echo $IP
dig @$IP evil.ip.com &
sleep 0.1
done


Could you please explain how i can set more Ip adresses for the IP=

the Dig command needs to try them 1 after each other.

like IP='130.123.54.34 130.123.54.35 etc..' (is that possible?)

thanks

-Terrery


Top
 Profile  
 PostPosted: Mon May 23, 2011 9:50 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Code:
while [ "2" > "1" ];

That is a bad example. It will redirect the output of the command 2 to a file named 1. While technically this will return a 'true' on each pass as long as you can write a file to the directory, it's bad practice. I assume you meant while [ 2 -gt 1 ], but I'd rather use while :


Top
 Profile  
 PostPosted: Mon May 23, 2011 12:12 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
terrery wrote:
Could you please explain how i can set more Ip adresses for the IP=
the Dig command needs to try them 1 after each other.
like IP='130.123.54.34 130.123.54.35 etc..' (is that possible?)


I would suggest something like the following:
Code:
for ip in 130.123.{0..255}.{0..255}; do
dig @$ip evil.ip.com
done

Don't use an ampersand after the dig command as that will start the dig process as a background task.


Top
 Profile  
 PostPosted: Mon May 23, 2011 2:06 pm   

Joined: Mon May 23, 2011 4:52 am
Posts: 4
Quote:
I would suggest something like the following:
Code:
for ip in 130.123.{0..255}.{0..255}; do
dig @$ip evil.ip.com


The 'for ip in' works just fine with all the resolvers(ip's) after each other, but were do i put the 'While :' if i use "for ip in do"?

Code:
for IP in 130.123.{0..255}.{0..255};
while :
do
echo $IP
dig @$IP evil.ip.com
sleep 0.1
done

Get a syntax error when i try this setup ^^ and when i place it above with another do or without do, it says 'unexpected end of file (syntax error)'.

Cheers,

-Terrery


Top
 Profile  
 PostPosted: Mon May 23, 2011 10:26 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
It's
Code:
while <condition>
do
<codeblock>
done

and
Code:
for <variable> in <value1> [<value2> [<...>]]
do
<codeblock>
done

If you want to combine/nest those, you have to write one inside the <codeblock> of the other. Just make sure you write both statements completely. It sounds to me you were missing a 'done' from one of the loops, since bash was complaining about 'unexpected end of file'.


Top
 Profile  
 PostPosted: Tue May 24, 2011 1:45 am   

Joined: Mon May 23, 2011 4:52 am
Posts: 4
Thank you Patsie.

Got it all working like i wanted to. :B

Cheers,

-Terrery


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP