Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Determining a Machine's IP Address from its "ipconfig" Output  RSS feed

 
Kevin Simonson
Ranch Hand
Posts: 219
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I spend a significant amount of time each day in my town's public library, that has a room with twenty terminals in it, each with a keyboard and mouse. At the computer I'm at right now I type in, "hostname" and get the response, "QUIET-8"; I type in, "ipconfig" and get the response:

Windows IP Configuration


Ethernet adapter Local Area Connection 2:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::d80f:ecbf:6b5:f02%13
IPv4 Address. . . . . . . . . . . : 10.0.215.69
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 10.0.215.1

Tunnel adapter isatap.{33CDB4EB-AE1F-4113-8DFA-A3797613E3FA}:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Tunnel adapter Teredo Tunneling Pseudo-Interface:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

And today (a different day) at the computer I'm at I type in, "hostname" and get the response, "Quiet-7"; I type in, "ipconfig" and get the response:

Windows IP Configuration


Ethernet adapter Local Area Connection 2:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::acb1:6352:1d6e:60fe%15
IPv4 Address. . . . . . . . . . . : 10.0.215.75
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 10.0.215.1

Tunnel adapter isatap.{6A77E4D5-B82C-4AE8-B839-B2321D6C4461}:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Tunnel adapter Local Area Connection* 11:

Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :

Tunnel adapter Teredo Tunneling Pseudo-Interface:

Media State . . . . . . . . . . . :
Connection-specific DNS Suffix . :

Now I've written code before that uses a socket between two machines so that each machine communicates with the other. But as I understand it, at least one of the machines needs to know the IP address of the other. How can I tell from the "ipconfig" outputs above what the IP addresses are for machines "QUIET-8" and "Quiet-7"?
 
Paul Clapham
Sheriff
Posts: 22215
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says right there:

IPv4 Address. . . . . . . . . . . : 10.0.215.69


It also tells you the IPv6 address, if you want, but in a local network like you've got there you don't really need to concern yourself with that.
 
Henry Wong
author
Sheriff
Posts: 23193
124
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The core java library has a java.net.InetAddress class, which can be used to get the network information. There is no need for the application to parse the "ipconfig" output.

Henry
 
Paul Clapham
Sheriff
Posts: 22215
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sort of surprised that your library terminals let you access the command line, but anyway, my question is what's the purpose of this question? I don't suppose you plan to run a server on the library's system, so what are you getting at here?
 
Tim Holloway
Bartender
Posts: 18607
68
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
The core java library has a java.net.InetAddress class, which can be used to get the network information. There is no need for the application to parse the "ipconfig" output.

Henry


Actually, that doesn't work as well as you think it does. InetAddress is to IP addresses what java.io.File is to files. Which is to say, it's a container for an IP address, not an actual IP address service method. It can resolve hostnames, allowing for the fact that a host can have multiple names, and it can resolve IP addresses, given that a host can not only have multiple IP addresses, but a single NIC can have multiple IP addresses. So - speaking from bitter experience - you cannot reliably get "the" IP address using this class.
 
Kevin Simonson
Ranch Hand
Posts: 219
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I'm sort of surprised that your library terminals let you access the command line, but anyway, my question is what's the purpose of this question? I don't suppose you plan to run a server on the library's system, so what are you getting at here?

As I said, the terminals in my library each have one keyboard and one mouse. There are a lot of kids who come in to the library to play games, one of which I know personally, my neighbor from down the street, Weston. I thought Weston might enjoy it if I programmed a simple tennis game, like Pong, that he could play with some of his friends, or even on some occasions with me. But in order to control the two paddles that would be involved, I would need two mice, not just one. So I thought I could put one player on one terminal (with its mouse), and the other on another terminal (with its mouse), and use a socket for the two terminals to communicate with each other. Does that answer your question?
 
Paul Clapham
Sheriff
Posts: 22215
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really. You're saying you plan to write an application which you will install on the library's system?
 
Paul Clapham
Sheriff
Posts: 22215
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And by the way you don't need to know the IP address of the server when you try to connect to it, knowing the computer name is sufficient.
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:And by the way you don't need to know the IP address of the server when you try to connect to it, knowing the computer name is sufficient.


I find in my Uni I do not need admin access to run java programs, even ones with server sockets
 
Tim Holloway
Bartender
Posts: 18607
68
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:And by the way you don't need to know the IP address of the server when you try to connect to it, knowing the computer name is sufficient.


Only if there's something that can resolve that computer name to an IP address. I've got a computer named "Fred", but no other machine knows that because it's not registered as such in DNS and I don't have it recorded in any "hosts" files.

Eddie Vanda wrote:I find in my Uni I do not need admin access to run java programs, even ones with server sockets


Providing Java was previously installed, no. Unless you attempt to listen on ports 4095 and below. That range does require admin privileges.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevin Simonson wrote:Does that answer your question?

Yes, but even if you can (or would want) to do it, your design assumes that every terminal in the library is managed by a single server. Now that may well be the case for your library, but it certainly isn't for all.

And that makes your design "brittle".

Winston
 
Kevin Simonson
Ranch Hand
Posts: 219
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Not really. You're saying you plan to write an application which you will install on the library's system?

I'm not planning on installing anything on the library's system. I've got two jump drives, each of which has Java installed on it. One jump drive will also have sort of the client side of my program to play tennis, and the other jump drive will have the server side of my program. The code will open up a socket between the two machines the code is running on. The client side will monitor where the mouse is on its JPanel, and send that position across the socket. The server side will monitor where the mouse is on its JPanel, and will also keep track of the position of the ball. The server side will then decide where to display the two paddles and the ball, and actually display them on its JPanel, and will direct the client side (across the socket) to display them as well.

So while the users are running these two Java programs, it will appear to be one game, that both of the users can see.
 
Kevin Simonson
Ranch Hand
Posts: 219
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
Kevin Simonson wrote:Does that answer your question?

Yes, but even if you can (or would want) to do it, your design assumes that every terminal in the library is managed by a single server. Now that may well be the case for your library, but it certainly isn't for all.

Are you saying that I can only open up a socket between programs run on two terminals if those terminals are managed by a single server?

Winston Gutkowski wrote:And that makes your design "brittle".

I definitely don't want a brittle design.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65970
140
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Run your game on your own server on the web and connect to it via the browser. That way, you can run it anywhere, anytime.
 
Henry Wong
author
Sheriff
Posts: 23193
124
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevin Simonson wrote:
Winston Gutkowski wrote:
Yes, but even if you can (or would want) to do it, your design assumes that every terminal in the library is managed by a single server. Now that may well be the case for your library, but it certainly isn't for all.

Are you saying that I can only open up a socket between programs run on two terminals if those terminals are managed by a single server?


Hate to point this out, but this side discussion may just be a distraction. Take a look at the first post again. These are simply Windows boxes. And both machines are on the same subnet -- that is obviously, on a private network. Arguably, they may be virtual machines on a virtual network, but for all intents and purposes, it should work the same... and can be confirmed with a simple check.

Back to the original question. We already answered the question on how to determine the IP address from the output. Did you try using the addresses? Did it work? And if so, then this side discussion is kinda moot.

Henry
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get back to the originial post, it would seem to me that he wants to start his server with his stick, give another stick(s) to his buddy(ies) and play the game.

He would set up a temp server, perhaps on port 80 as that is most likely to go to the local router, though this is not a given, and wait for others to find him.

The others could get an InetAddress from a temporary serversocket on their clients and use the ip address from that to do a search, going up and down from that client's address.

All that assumes they are on the same subnet and that the router lets requests through locally for port 80 and that the timeout is reasonably short.

Good Luck!
 
Henry Wong
author
Sheriff
Posts: 23193
124
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eddie Vanda wrote:
All that assumes they are on the same subnet and that the router lets requests through locally for port 80 and that the timeout is reasonably short.


If I had to guess at the most likely issue to be encountered, I would say that it would be the Windows firewall. By default, Windows do not allow incoming connections -- and I highly doubt that the library system administrators would disable the firewall.

Henry
 
Paul Clapham
Sheriff
Posts: 22215
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:I highly doubt that the library system administrators would disable the firewall.


I'm still boggling about library administrators who allow people to run arbitrary software on their network. So it's possible that Kevin could disable the firewall himself if necessary.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!