Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Convert ip-addresses in file with hostname
Hi all!

I am working on a project in which there's something to be done with
which I need a little help: a file containing lines with ip-addresses
which should be replaced by the hostname of the servers instead of the
ip-addresses.

I tried several ways, without succes. Most close I came with a "for i"
statement
and a AWK {print $5} construction. However, I need some directives to
complete the job of the conversion from the ip-address to the
hostname. what do I use?
nslookup, dig, hostname?

I assumed something like this:

hosts=/tmp/temprep0

for ip in $hosts ; do
if [ ".$host" = 10.65. ] ; then
for i in `netstat -in | awk
'{if(substr($1,1,1)!="N")print$1}' | sed 's/\*//g'` ; do
ifconfig $i
done
continue
fi
sed 's/$/ /' < /etc/hosts > $tmp2 || die "sed failed"
grep -i "[  ]$host[  ]" $tmp2 > $tmp
if [ $? = 0 ] ; then
head -1 $tmp | awk '{printf("%-30s  %s\n",$2,$1)}'
else
if [ -r /etc/resolv.conf ] ; then
nslookup $host 2>&1 | sed 's/[  ]*,[  ]*/ /' >
$tmp
fgrep '***' $tmp > /dev/null
if [ $? = 0 ] ; then
echo "$prog: host '$host' not found" 1>&2
continue
fi

Anyone?

Thanx in advance

Report this thread to moderator Post Follow-up to this message
Old Post
Bas
11-21-04 01:55 PM


Re: Convert ip-addresses in file with hostname
In article <cnklp8$28u$1@aken.eed.ericsson.se>, Michael Tosch wrote:
> In article <717da987.0411190122.48d918e7@posting.google.com>, bvweelde@che
llo.nl (Bas) writes: 
>
> Sorry, I dont understand what your script does and what it should do
> instead. An example would be helpful.
>
> Is it just about IP-to-host translation?
> Then this works best:
>
> getent hosts $ip | awk '{print $2}'

That assumes you have 'getent', which on my HP-UX boxes I do not...

Kevin


Report this thread to moderator Post Follow-up to this message
Old Post
Kevin Collins
11-25-04 01:55 AM


Re: Convert ip-addresses in file with hostname
In article <cnklp8$28u$1@aken.eed.ericsson.se>, Michael Tosch wrote:
> In article <717da987.0411190122.48d918e7@posting.google.com>, bvweelde@che
llo.nl (Bas) writes: 
>
> Sorry, I dont understand what your script does and what it should do
> instead. An example would be helpful.
>
> Is it just about IP-to-host translation?
> Then this works best:
>
> getent hosts $ip | awk '{print $2}'

That assumes you have 'getent', which on my HP-UX boxes I do not...

Kevin


Report this thread to moderator Post Follow-up to this message
Old Post
Kevin Collins
11-29-04 08:58 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:33 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.