How to detect programmatically if my machine is behind a firewall

How to detect programmatically if my machine is behind a firewall

Post by swaroop196 » Sun, 07 Mar 2004 02:37:21


Hello:

Is it possible to programmatically (in Java, of course) detect if
my machine is running behind a firewall or a router? I would
appreciate any help/tips/pointers/advice that you can provide. A
potentially silly way would be to send an HTTP request to
http://www.yqcomputer.com/ and compare the IP address in the response to
the one that I think I have (maybe determined by creating a socket?).

Thanks in advance,
Swaroop
 
 
 

How to detect programmatically if my machine is behind a firewall

Post by nos » Sun, 07 Mar 2004 03:34:01

chances are pretty high that there is a router between your
machine and sites on the internet.

 
 
 

How to detect programmatically if my machine is behind a firewall

Post by Jeeve » Sun, 07 Mar 2004 10:45:46


XXXX@XXXXX.COM (Swaroop Kumar) wrote in



Everyone is "behind a router". Are you trying to find out if there's a
NAT device or application between the network and the destination
address?
 
 
 

How to detect programmatically if my machine is behind a firewall

Post by swaroop196 » Sun, 07 Mar 2004 10:49:16

Thanks for the quick reply.

Sorry if I didn't make my meaning clear, but by "my", I meant the
machine that the program runs on, not specifically my machine. We are
in the design stages of a program that will run in large institutions,
which could have machines with class A or class B subnet addresses and
may not be behind a router.

Thanks again,
Swaroop
 
 
 

How to detect programmatically if my machine is behind a firewall

Post by Missaka Wi » Mon, 08 Mar 2004 14:38:27

Hi,

No it is not possible. BTW, if you need to talk to any machine on the
internet, then by definition you must be behind a router - no
exceptions. But I think what you mean is a firewall, NAT (network
address translation) or proxy server, right?

You can do a few things to guess:

* if your ip is 192.X.X.X or 10.X.X.X then you have a private ip address
and if you need to talk to any other machine on the internet, you must
be behind a router/firewall/proxy that is doing NAT.

* see if your JVM is using SOCKS, or a proxy to get at web addresses. If
so you are behind a firewall.

* attempt to make connections to a known ip address on the internet.
Connect with http, https, telnet, and some other arbitrary ports. Based
on the successes and/or failures you can determine the nature of the
firewall.

* if you can, obtain the routing info for your server. I am unsure as
to how to do this directly from Java, however the following command on
UNIX and Windows (I think - NT/2000/XP) will reveal routes, interfaces,
and gateways (router/firewall):

netstat -rn

Cheers,
Misk









--
========================================================================
Missaka Wijekoon (a.k.a. Misk) XXXX@XXXXX.COM
Sr. Software Engineer http://www.yqcomputer.com/
VillageEdocs
========================================================================