a question for java networking experts

Discussion in 'Java' started by John Galt, Jul 15, 2004.

  1. John Galt

    John Galt Guest

    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
     
    John Galt, Jul 15, 2004
    #1
    1. Advertising

  2. John Galt

    zzyzx Guest

    John Galt wrote:

    > 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: (Phil Hanna)
    Newsgroups:
    comp.lang.java.misc,comp.lang.java.programmer,comp.lang.java.help,comp.lang.java.developer
    References: <>
    <>
    <>
    <pF2Ja.71390$Pc5.38137@fed1read01> <bd2nat$t66$>
    <A47Ja.71452$Pc5.70727@fed1read01> <bd5bvk$7gp$>

    On Mon, 23 Jun 2003 00:53:21 +0200, Jezuch <> wrote:

    >U┬┐ytkownik Shripathi Kamath napisa┬│:
    >> Which is why I said "not necessarily". He might want to run it only

    on a
    >> variety of platforms on which the code *may* be the same.
    >>
    >> Besides, I addressed that in the rest of the post you snipped away.

    >
    >Oh... Sorry about that :)
    >This "not necessarily" seemed to be referring to "Sounds like you need

    some
    >JNI and platform specific code".
    >--
    >Ecce Jezuch
    >"If I was the king of all the rotten, stealing filth from those forgotten,
    >Would you be my queen?" - P. Keenan
    >

    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;
    }
    }
    --
    Phil Hanna
    Author of JSP 2.0: The Complete Reference
    http://www.philhanna.com
    http://www.philhanna.com
     
    zzyzx, Jul 15, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rahul Sharma

    Is there Java.Networking group

    Rahul Sharma, Jul 23, 2003, in forum: Java
    Replies:
    6
    Views:
    422
    Jezuch
    Jul 23, 2003
  2. Robert Olofsson

    Re: Java I/O for Networking

    Robert Olofsson, Aug 22, 2003, in forum: Java
    Replies:
    2
    Views:
    412
    Robert Olofsson
    Aug 24, 2003
  3. VisionSet

    java to java networking

    VisionSet, Nov 19, 2003, in forum: Java
    Replies:
    0
    Views:
    284
    VisionSet
    Nov 19, 2003
  4. Steve R. Burrus

    Need help w. Java Networking.

    Steve R. Burrus, Jun 5, 2004, in forum: Java
    Replies:
    12
    Views:
    774
    Bryce
    Jun 7, 2004
  5. Winston

    Java Networking

    Winston, Mar 10, 2005, in forum: Java
    Replies:
    1
    Views:
    337
    iNFiDEL
    Mar 16, 2005
Loading...

Share This Page