a question for java networking experts

J

John Galt

I have a situation where:

- client connects to a server, some java servlet, say
- servlet wants to know the address of the client's gateway (i.e
"Default Gateway" when you do ipconfig or ifconfig)

Is there a Java API call to do this? Can it be done by a servlet? Can
the servlet send down an applet to do the job? Is there an applet API
call of some sort to probe for this kind of low-level networking info?
That is, is there an applet API call to do the equivalent of ifconfig
or arp commands?

thanks in advance,
John
 
Z

zzyzx

John said:
I have a situation where:

- client connects to a server, some java servlet, say
- servlet wants to know the address of the client's gateway (i.e
"Default Gateway" when you do ipconfig or ifconfig)

Is there a Java API call to do this? Can it be done by a servlet? Can
the servlet send down an applet to do the job? Is there an applet API
call of some sort to probe for this kind of low-level networking info?
That is, is there an applet API call to do the equivalent of ifconfig
or arp commands?

thanks in advance,
John

Check out the Response from Phil Hanna over a year ago to a similar
question.


-------- Original Message --------
Subject: Re: How to get MAC address for local machine?
Date: Mon, 30 Jun 2003 23:24:48 GMT
From: (e-mail address removed) (Phil Hanna)
Newsgroups:
comp.lang.java.misc,comp.lang.java.programmer,comp.lang.java.help,comp.lang.java.developer
References: <[email protected]>
<[email protected]>
<[email protected]>
<pF2Ja.71390$Pc5.38137@fed1read01> <[email protected]>
<A47Ja.71452$Pc5.70727@fed1read01> <[email protected]>

U¿ytkownik Shripathi Kamath napisa³:

Oh... Sorry about that :)
This "not necessarily" seemed to be referring to "Sounds like you need some
JNI and platform specific code".
Operating system specific, of course, but this works for Windows NT:

import java.io.*;
import java.net.*;
import java.util.*;
import java.util.regex.*;

public class GetMac
{
public static void main(String[] args)
throws IOException
{
String address = new GetMac().getMacAddress();
System.out.println(address);
}

public String getMacAddress() throws IOException
{
String macAddress = null;
String command = "ipconfig /all";
Process pid = Runtime.getRuntime().exec(command);
BufferedReader in =
new BufferedReader(
new InputStreamReader(pid.getInputStream()));
while (true) {
String line = in.readLine();
if (line == null)
break;
Pattern p = Pattern.compile(".*Physical Address.*: (.*)");
Matcher m = p.matcher(line);
if (m.matches()) {
macAddress = m.group(1);
break;
}
}
in.close();
return macAddress;
}
}
 

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,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top