LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-24-2003, 04:39 AM   #1
Robert0380
LQ Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Rep: Reputation: 47
script to parse out ip


i'd like to parse out the ip address of a given hostname from nslookup or dig. even better would be a way to get nslookup just to print out the ip only (did a man nslookup but didnt see the option).

here is what i know:

nslookup hostname -sil will print out 7 lines:

1. Server: IP.OF.Nameserver
2. Address: IP.OF.Nameserver:portnumber
3.Blank Line
4.Non-authoritative answer:
5.Name: hostname
6.Address: IP.OF.Host
7.Blank Line


knowing this, the script would only have to grab the 6th line (5 if you count from 0) and then the second word of that line (if you delimit based on white space).

I can do this in Java if the information from nslookup is stored to a file but that's is not very efficient at all because after i get the ip i have to do some DNS stuff with it to update an IP address.

i'd rather not use perl, but i'll take any suggestions or code slices anyone is willing to give me for this. right now im looking into some shell scripting but i thought i'd ask here in the meantime.

Thanks,

Robert

Last edited by Robert0380; 08-24-2003 at 04:43 AM.
 
Old 08-24-2003, 05:12 AM   #2
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
Instead of nslookup you should use host. So your command looks like host -t a www.linuxquestions.org
Code:
www.linuxquestions.org has address 64.179.4.146
In this case:

Code:
host -t a www.linuxquestions.org | awk '{print $4}' | egrep ^[1-9]
The egrep part is required because of aliases (CNAME). You can probably adjust the egrep ... I'm not yet that familar with regular expressions :-)

Last edited by markus1982; 08-24-2003 at 05:15 AM.
 
Old 08-24-2003, 06:09 AM   #3
Robert0380
LQ Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Original Poster
Rep: Reputation: 47
PERFECT.

also, that iptables script u wrote a while back came in handy also.

thanks man.
 
Old 08-24-2003, 06:24 AM   #4
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
No problem ... do you want to transfer some $ to my bank account? :-) Just joking of course!
 
Old 08-24-2003, 06:33 AM   #5
Robert0380
LQ Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Original Poster
Rep: Reputation: 47
lol
 
Old 08-24-2003, 06:47 AM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
You could forget awk too if you use resolveip:
resolveip -s www.linuxquestions.org
 
Old 08-31-2003, 06:01 AM   #7
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
Well resolveip is only included in the mysql server package in Debian.
 
Old 08-31-2003, 06:36 AM   #8
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Rep: Reputation: 33
Quote:
Originally posted by markus1982
Well resolveip is only included in the mysql server package in Debian.
Thanx guys , I learnt a new thing
all these days I used

ping -c 1 www.linuxquestions.org | cut -d " " -f 3 | egrep 1

to find the i.p
 
  


Reply



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
Parse String in a Bash script jimwelc Linux - Newbie 8 11-09-2012 07:47 AM
Script help (parse website) Vgui Linux - General 3 08-22-2005 06:37 PM
bash script help to parse out text slack guy Linux - Newbie 3 12-30-2004 08:42 AM
Need help with perl/bash script to parse PicBasic file cmfarley19 Programming 13 11-18-2004 05:06 PM
use php script to parse a file. blackzone Linux - Software 1 07-07-2004 04:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:41 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
Open Source Consulting | Domain Registration