How to get IP Address of a remote host

  • Thread starter gimme_this_gimme_that
  • Start date
G

gimme_this_gimme_that

I'm working on a project where I connect to a remote host using its
name dahdahdah.somesite.com.

The owner of somesite.com has production and development versions of
dahdahdah - and the one you connect to should be determined by your
local hosts file.

I'd like to confirm I'm connecting to the development version.

How do I get the IP address of the machine I'm connecting to?

I'm using Apache's HttpClient package and a GetMethod class - but a
solution that uses only java.net.* would be fine.

Thanks.
 
A

Arne Vajhøj

I'm working on a project where I connect to a remote host using its
name dahdahdah.somesite.com.

The owner of somesite.com has production and development versions of
dahdahdah - and the one you connect to should be determined by your
local hosts file.

I'd like to confirm I'm connecting to the development version.

How do I get the IP address of the machine I'm connecting to?

I'm using Apache's HttpClient package and a GetMethod class - but a
solution that uses only java.net.* would be fine.

ipnum = InetAddress.getByName(ipnam).getHostAddress();

maybe.

Arne
 
M

Mark Space

The owner of somesite.com has production and development versions of
dahdahdah - and the one you connect to should be determined by your
local hosts file.

This sounds like the worst idea imaginable. You hard code the server
name, and then edit the hosts file? Why not just supply the host name
as a parameter or in a config file? At worst, if it has no name, just
supply the IP address instead of the name.
 
O

Owen Jacobson

This sounds like the worst idea imaginable.  You hard code the server
name, and then edit the hosts file?  Why not just supply the host name
as a parameter or in a config file?  At worst, if it has no name, just
supply the IP address instead of the name.

Because that would imply planning ahead.

I'm reasonably sure that when the site was created it only had a
single, production version. Later, someone sane came along and said
"hey, let's not do our dev on the live site." Either that, or some
developer figured that since he didn't mind modifying his own /etc/
hosts, and was smart enough not to forget to undo his changes later,
nobody else would mind either and everyone else would be as smart.

We're fighting with this at $DAYJOB on a somewhat epic scale; because
of recent changes to the URL structure of our site, we now have a set
of scripts that assumes you have the www.YOURNAMEHERE.dev.example.com
name ( in /etc/hosts and goes to a content switch and DNS server and
creates foo.YOURNAMEHERE.example.com, bar.YOURNAMEHERE.example.com,
etc and sets up the appropriate rules in the content switch -- but it
all still relies on you modifying your hosts file first.

Not that I'm bitter and grumpy.

-o
 
G

gimme_this_gimme_that

This sounds like the worst idea imaginable.  You hard code the server
name, and then edit the hosts file?  Why not just supply the host name
as a parameter or in a config file?  At worst, if it has no name, just
supply the IP address instead of the name.

The host name associated with both IPs is the same.

So it doesn't matter if the host name is configurable - say in a
database - or hard coded.
 
L

Lasse Reichstein Nielsen

The owner of somesite.com has production and development versions of
dahdahdah - and the one you connect to should be determined by your
local hosts file.

I'd like to confirm I'm connecting to the development version.

How do I get the IP address of the machine I'm connecting to?

Do a manual DNS lookup, e.g.,
$ nslookup dahdahdah.somesite.com

If you need to do it programmatically, then do the equivalent in Java,
e.g., java.net.InetAddress#getByName(String).

/L
 
N

Nigel Wade

Lasse said:
Do a manual DNS lookup, e.g.,
$ nslookup dahdahdah.somesite.com

nslookup doesn't use the local resolver, it makes a direct DNS request and
bypasses any local host file [mis]configurations. Ping would be the simplest
solution as it reports the IP it is attempting to ping.
 
M

Mark Space

The host name associated with both IPs is the same.

Err, yeah. That's my point. See Owen's post above for a good real live
example why this is a bad idea.
So it doesn't matter if the host name is configurable - say in a
database - or hard coded.

What? lurn 2 tcp/ip pls kthxby
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top