LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-04-2009, 08:01 PM   #1
webmazter
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Rep: Reputation: 0
Domain to ip checker


i have 256 ips all reversed to domain names.
I am wanting to autocheck them to see if they match.

so far searching google this is all i have come up with.

host 72.8.167.104 |cut -f5 -d' '"
to show the name
hoplesly.desperate.info.

then
host hoplesly.desperate.info
hoplesly.desperate.info has address 72.8.167.104
to show the ip.

im not sure this is the way to check
basicy i want to compare each ip to host and host to ip
for each ip on the range 72.8.167
anytime that i want to check and see if they are all working and to show me if they are not the same or equal.
 
Old 07-04-2009, 08:52 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
Code:
check() { # (find a way to) prep the subnet range yourself then give one IP address as argument:
IP="$1"; PTR=`echo $IP | awk -F'.' '{print $4"."$3"."$2"."$1".in-addr.arpa"}'`
echo -en "$IP match: "; [ `host -t PTR $PTR 2>/dev/null|awk '{print $NF}'` \
= `dig +short -x $IP` ] && echo yes || echo no; }
 
Old 07-04-2009, 09:06 PM   #3
webmazter
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Original Poster
Rep: Reputation: 0
that looks like it should be just right, shame its not a working line.
 
Old 07-04-2009, 10:40 PM   #4
cmdln
Member
 
Registered: Apr 2009
Location: Lawrence, KS
Distribution: Debian, Centos
Posts: 102
Blog Entries: 1

Rep: Reputation: 24
Quote:
Originally Posted by webmazter View Post
that looks like it should be just right, shame its not a working line.
Bah its really ugly but it seems to work for me. Prints error if reverse entry does not match forward entry. Note: this is ugly and hacky and will probably break easily if you have something like cnames or multiple a records.

domipcheck.sh
Code:
#!/bin/bash
# Pass in domain
# Return 0 if the ip mapped to the domain is the same as the reverse ip lookup

DOMAIN=$1
DOMAIN_IP=$(host $DOMAIN)
RETVAL=$?
if [[ $RETVAL -gt 0 ]]; then
        echo "No IP for host $DOMAIN"
        exit 1
else
        DOMAIN_IP=$(echo $DOMAIN_IP | cut -d " " -f 4)
        IP_DOMAIN=$(dig -x $DOMAIN_IP | grep -A1 "ANSWER SECTION"| awk '{print $5}')
        IP_DOMAIN=$(echo $IP_DOMAIN | cut -c -$(echo $(echo $(IP_DOMAIN | wc -c)-2 | bc))
        if [[ $IP_DOMAIN == $DOMAIN ]]; then
                exit 0
        fi

fi
so take a txt file with one domain/line an do something like

for domain in $(cat file.txt);do
domipcheck.sh $domain;
done;

Last edited by cmdln; 07-04-2009 at 10:43 PM. Reason: added example
 
Old 07-05-2009, 12:22 AM   #5
webmazter
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Original Poster
Rep: Reputation: 0
can u help me with this error i changed nothing from your file.
[root@shell1 ~]# ./dm
./domipcheck.sh: line 14: unexpected EOF while looking for matching `)'
./domipcheck.sh: line 20: syntax error: unexpected end of file
[root@shell1 ~]#

Quote:
#!/bin/bash
# Pass in domain
# Return 0 if the ip mapped to the domain is the same as the reverse ip lookup

DOMAIN=$1
DOMAIN_IP=$(host $DOMAIN)
RETVAL=$?
if [[ $RETVAL -gt 0 ]]; then
echo "No IP for host $DOMAIN"
exit 1
else
DOMAIN_IP=$(echo $DOMAIN_IP | cut -d " " -f 4)
IP_DOMAIN=$(dig -x $DOMAIN_IP | grep -A1 "ANSWER SECTION"| awk '{print $5}')
IP_DOMAIN=$(echo $IP_DOMAIN | cut -c -$(echo $(echo $(IP_DOMAIN | wc -c)-2 | bc))
if [[ $IP_DOMAIN == $DOMAIN ]]; then
exit 0
fi

fi
 
Old 07-05-2009, 01:43 AM   #6
cmdln
Member
 
Registered: Apr 2009
Location: Lawrence, KS
Distribution: Debian, Centos
Posts: 102
Blog Entries: 1

Rep: Reputation: 24
Quote:
Originally Posted by webmazter View Post
can u help me with this error i changed nothing from your file.
[root@shell1 ~]# ./dm
./domipcheck.sh: line 14: unexpected EOF while looking for matching `)'
./domipcheck.sh: line 20: syntax error: unexpected end of file
[root@shell1 ~]#
Try the attached file it seems to work for me.
Attached Files
File Type: txt domipcheck.sh.txt (494 Bytes, 9 views)
 
Old 07-05-2009, 04:12 AM   #7
micxz
Senior Member
 
Registered: Oct 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Code:
#!/bin/bash

DOMAIN=$1
DOMAIN_IP=`dig +short $DOMAIN`
DOMAIN_TEST=$(host $DOMAIN)
RETVAL=$?

if [ $RETVAL -gt 0 ]; then
echo "No IP for host $DOMAIN"
exit 1
else
IP_DOMAIN=`dig -x $DOMAIN_IP +short`
if [ $IP_DOMAIN != $DOMAIN"." ]; then
echo $DOMAIN "NOT REVERSE FOR" $DOMAIN_IP -$IP_DOMAIN-
exit 0
fi
if [ $IP_DOMAIN == $DOMAIN"." ]; then
echo $DOMAIN "REVERSES TO" $DOMAIN_IP
exit 0
fi
fi
Here's a my modified version of some of the above examples. There is a better way I'm sure.

Last edited by micxz; 07-05-2009 at 04:17 AM. Reason: spelling
 
Old 07-05-2009, 05:37 AM   #8
micxz
Senior Member
 
Registered: Oct 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
I realized that you wanted a script to go through the subnet and test reverse rather then test domain's like the examples. Oops' So I started writing another for fun and stopped when I realized the output started to look well... lame. I don't know what your up to but the ip block you posted when reverse are checked

micxz@phybernuker:~/scr> ./chkreverse
NO REVERSE FOR 72.8.167.1
NO REVERSE FOR 72.8.167.2
NO REVERSE FOR 72.8.167.3
NO REVERSE FOR 72.8.167.4
NO REVERSE FOR 72.8.167.5
NO REVERSE FOR 72.8.167.6
NO REVERSE FOR 72.8.167.7
NO REVERSE FOR 72.8.167.8
NO REVERSE FOR 72.8.167.9
imma.packet.your.root.org.in.
long.root.org.in.
free.root.org.in.
taste.my.root.org.in.
wish.i.had.your.root.org.in.
i.want.your.root.org.in.
gimmie.root.org.in.
only.i.have.root.org.in.
show.me.your.root.org.in.
i.hack.root.org.in.
i.like.herb.n.root.org.in.
there.is.no.irc-god.us.
show.me.irc-god.us.
i.am.the.irc-god.us.
feel.my.power.of.irc-god.us.
pray.before.your.irc-god.us.
lesbian.irc-god.us.
my.lover.is.the.irc-god.us.
kiss.the.irc-god.us.
say.no.to.the.irc-god.us.
not.even.a.real.irc-god.us.
^C
micxz@phybernuker:~/scr>

ON AND ON AND ON with words I'm not allow to post here... So I'm not helping anymore.
 
Old 07-05-2009, 11:58 AM   #9
webmazter
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Original Poster
Rep: Reputation: 0
Yes some nasty vhosts, this is what the company uses for hiding the ips.
I wish you would keep helping, seems im so close now thanks to all your help.
Still tho nothing seems to work exactly that way it should.

I am doing this as a way to check to see if the domains = the ip.
This way when i setup a PTR record that i dont have to keep dnsing every host ip to see if it works.

For the last example i got.
./domipcheck.sh: line 13: [: too many arguments
./domipcheck.sh: line 17: [: too many arguments
 
Old 07-05-2009, 12:04 PM   #10
cmdln
Member
 
Registered: Apr 2009
Location: Lawrence, KS
Distribution: Debian, Centos
Posts: 102
Blog Entries: 1

Rep: Reputation: 24
You cant hide ips.

I suspect this is a spam farm so I can't support that for free either.
 
Old 07-05-2009, 12:30 PM   #11
webmazter
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Original Poster
Rep: Reputation: 0
actully no,
its irc hosting
shell hosting etc
www.shellxnet.com
 
Old 07-05-2009, 02:20 PM   #12
micxz
Senior Member
 
Registered: Oct 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Quote:
Originally Posted by webmazter View Post
Yes some nasty vhosts, this is what the company uses for hiding the ips.
Maybe they should use the IP's to hide the names (lol). BTW hiding either with PTR's does not make sense.

And you can only pass one arg at a time with the example I posted. Use a loop to get the results for many names as posted earlier by mndln

So tell what's your involvement with this company? What's you role in solving reverse lookups?

Last edited by micxz; 07-05-2009 at 02:21 PM.
 
Old 07-05-2009, 04:10 PM   #13
webmazter
LQ Newbie
 
Registered: Jul 2009
Posts: 7

Original Poster
Rep: Reputation: 0
I am the owner, and im tired of checking vhosts.
i created 50 new ones last week and have to check to make sure they all resolve.
i tried your new script but no luck yet again.
seems your bash and my bash are incompatible i guess.
./a: line 13: [: ==: unary operator expected
./a: line 10: [: ==: unary operator expected
./a: line 13: [: ==: unary operator expected
 
Old 07-05-2009, 04:49 PM   #14
micxz
Senior Member
 
Registered: Oct 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
OK. Last one.

Code:
#!/bin/bash

IP_PRE=72.8.167.

for (( i = 1; i <= 255; i++ ))
do
IP2CHECK=$IP_PRE$i
DOMREV=`dig -x $IP2CHECK +short`
DOMVER=`dig +short $DOMREV`
if [ "$DOMREV" == "."  ]; then
echo "NO REVERSE FOR" $IP2CHECK
elif
 [ "$DOMVER" == "$IP2CHECK" ]; then
echo $DOMVER "REVERSE MATCHES" $DOMREV
fi
done
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
exploit checker linuxtesting2 Linux - Security 3 07-05-2009 03:15 PM
IPtables - block subdomains (a.domain.com, b.domain.com, c.domain.com,...) benjalien Linux - Networking 6 06-24-2009 08:03 AM
Spell Checker Kahless LQ Suggestions & Feedback 4 07-16-2007 12:35 AM
Spell Checker royleith Linux - Desktop 2 06-15-2007 08:30 AM
Proxy Checker tailender Linux - Networking 0 11-20-2006 07:38 AM


All times are GMT -5. The time now is 02:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration