how to get ip

graudeejs

Son of Beastie

Reaction score: 694
Messages: 4,615

How get get ip address in sh or perl, If I know server adress?

For example I want to get IP for example.com
How to do that in sh or perl? (perl preferred)
 
OP
OP
graudeejs

graudeejs

Son of Beastie

Reaction score: 694
Messages: 4,615

Code:
# arp freebsd.org
freebsd.org (69.147.83.40) -- no entry
works better (for what I want)

perhaps, there's tool/cmd to get IP only?
 

anemos

Member

Reaction score: 16
Messages: 58

Code:
#!/usr/bin/perl -w

use strict;
use Socket;

my $raw_ip;
my $dotted_ip;

$raw_ip = gethostbyname("freebsd.org");

if (defined $raw_ip) {
        $dotted_ip = inet_ntoa($raw_ip);
        print $dotted_ip;
} else {
        print 'Not found';
}
Code:
$ ./getip.pl
$ 69.147.83.40
 

Voltar

Active Member

Reaction score: 24
Messages: 191

Alt said:
I would do like this

Or if you need only 1 ip, in shell
You can remove the need for awk by using "+short", i.e.



Code:
vulcan# dig +short freebsd.org
69.147.83.40
vulcan# dig +short google.com
74.125.67.100
74.125.127.100
74.125.45.100
vulcan#
 
Top