Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding static routes  RSS feed

 
Matt Howard
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone think of an easy way to get my local IP Address for a specific network connection? I use several VPN's throughout the day, and when I sign on they change all my routes to send all traffic through them. So I run a batch file (I'm on Win 2K)with 2 lines like:
route change 0.0.0.0 MASK 0.0.0.0 222.22.2.2
(send all requests to my primary gateway)
route add 10.17.0.0 MASK 255.255.0.0 10.17.1.2
(only send requests to a 10.17 network through my VPN)
Well that's all fine and dandy except every time I sign on to the VPN I get a different address (10.17.1.2, 10.17.1.3 ...). I'd like to write a simple class to make the connection, get the IP Address assigned by that connection and then change the routes accordingly. I've tried java.net.InetAddress.getLocalHost() but that only returns my primary address. Is there any way to get an array of all the local IPs?
The only thing I can think of is to use Runtime to execute an ipconfig, and parse the results with a regex or something. Any ideas would be much appreciated.
 
Phil Doe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do the following:
InetAddress.getAllByName(hostname);
You'll get an array of InetAddress objects which you can iterate over them
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!