Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get IP Address of a remote host

0 views
Skip to first unread message

gimme_this...@yahoo.com

unread,
Jul 24, 2008, 8:48:04 PM7/24/08
to
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.

Arne Vajhøj

unread,
Jul 24, 2008, 8:53:09 PM7/24/08
to

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

maybe.

Arne

Mark Space

unread,
Jul 24, 2008, 9:42:28 PM7/24/08
to
gimme_this...@yahoo.com wrote:

> 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.

Owen Jacobson

unread,
Jul 24, 2008, 11:44:02 PM7/24/08
to
On Jul 24, 9:42 pm, Mark Space <marksp...@sbc.global.net> wrote:

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

gimme_this...@yahoo.com

unread,
Jul 25, 2008, 1:06:48 AM7/25/08
to
On Jul 24, 6:42 pm, Mark Space <marksp...@sbc.global.net> wrote:

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.

Lasse Reichstein Nielsen

unread,
Jul 25, 2008, 5:58:51 AM7/25/08
to
"gimme_this...@yahoo.com" <gimme_this...@yahoo.com> writes:

> 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
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'

Nigel Wade

unread,
Jul 25, 2008, 7:06:42 AM7/25/08
to
Lasse Reichstein Nielsen wrote:

> "gimme_this...@yahoo.com" <gimme_this...@yahoo.com> writes:
>
>> 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
>

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.

--
Nigel Wade

Mark Space

unread,
Jul 25, 2008, 2:51:03 PM7/25/08
to
gimme_this...@yahoo.com wrote:

> On Jul 24, 6:42 pm, Mark Space <marksp...@sbc.global.net> wrote:

>> 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.

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

0 new messages