obtaining the IP ADDRESS of an IP POHNE by its MAC ADDRESS

Discussion in 'Cisco' started by ProgDario, Apr 22, 2005.

  1. ProgDario

    ProgDario Guest

    HI,

    I'm developing a process that needs to obtain the IP ADDRESS of a IP
    PHONE, but I only know the MAC ADDRESS (sep number) of the target
    phone.

    On the DHCP SERVER installed, I see the 'Address Leases' table, and it
    contains the information I need, BUT I DON'T KNOW how to query this
    table.


    Any hint is appreciated.

    Thanks in advance!!

    :)ario
     
    ProgDario, Apr 22, 2005
    #1
    1. Advertising

  2. ProgDario

    John Smith Guest

    As this is a cisco newsgroup I'll attempt a cisco answer. Log into your
    router and type "show arp", it does what it says on the tin.

    Regards
    Paul

    "ProgDario" <> wrote in message
    news:...
    > HI,
    >
    > I'm developing a process that needs to obtain the IP ADDRESS of a IP
    > PHONE, but I only know the MAC ADDRESS (sep number) of the target
    > phone.
    >
    > On the DHCP SERVER installed, I see the 'Address Leases' table, and it
    > contains the information I need, BUT I DON'T KNOW how to query this
    > table.
    >
    >
    > Any hint is appreciated.
    >
    > Thanks in advance!!
    >
    > :)ario
    >
     
    John Smith, Apr 22, 2005
    #2
    1. Advertising

  3. ProgDario

    ProgDario Guest

    Thanks for the reply, but the answer is too low-level for my
    environment.

    I have to query the DHCP server via java but I don't have access to the
    switch configuration.

    I need a way to query the DHCP server directly, and extract the
    'Address Leases' list.

    Any ideas?


    Thanks


    :)ario
     
    ProgDario, Apr 22, 2005
    #3
  4. ProgDario

    John Smith Guest

    sorry I don't understand the workings of DHCP at that sort of level. Are you
    sure it's even possible? I suppose grabbing the arp table off the local
    machine is no good to you? "arp -a" from the command prompt

    "ProgDario" <> wrote in message
    news:...
    > Thanks for the reply, but the answer is too low-level for my
    > environment.
    >
    > I have to query the DHCP server via java but I don't have access to the
    > switch configuration.
    >
    > I need a way to query the DHCP server directly, and extract the
    > 'Address Leases' list.
    >
    > Any ideas?
    >
    >
    > Thanks
    >
    >
    > :)ario
    >
     
    John Smith, Apr 22, 2005
    #4
  5. ProgDario

    ProgDario Guest

    Yes, it could be useful, but if I am on a PC, how can I grab the ARP
    table on the DHCP SERVER that's on another PC?

    Thanks again!!

    :)ario
     
    ProgDario, Apr 22, 2005
    #5
  6. ProgDario

    Scooby Guest

    "ProgDario" <> wrote in message
    news:...
    > Yes, it could be useful, but if I am on a PC, how can I grab the ARP
    > table on the DHCP SERVER that's on another PC?
    >
    > Thanks again!!
    >
    > :)ario
    >


    I like using SNMP for stuff like this. If your DHCP server was on a cisco
    device, that would work. However, since it is on the PC, that makes it
    tough. You could perhaps use SNMP to query the switch that the device is
    connected to. Phones keep enough traffic going that the arp should always
    be in the table on the switch. It may not always be available on the PC,
    since the phone will just be communicating periodically to update the DHCP
    lease.

    Hope that helps,

    Jim
     
    Scooby, Apr 22, 2005
    #6
  7. ProgDario

    ProgDario Guest

    OK, I understand you are an expert in this sector, but unfortunately
    I'm a newbie, so your answer sounds difficult to understand.

    How can I query the switch? Does this mean that I have to prepare e
    SNMP query or something similar?


    Thanks


    :)ario
     
    ProgDario, Apr 22, 2005
    #7
  8. ProgDario

    Scooby Guest

    "ProgDario" <> wrote in message
    news:...
    > OK, I understand you are an expert in this sector, but unfortunately
    > I'm a newbie, so your answer sounds difficult to understand.
    >
    > How can I query the switch? Does this mean that I have to prepare e
    > SNMP query or something similar?
    >
    >
    > Thanks
    >
    >
    > :)ario
    >


    Well, I guess that it would help to know a little more what you are trying
    to do. Are you writing a program? What tool are you using for that?

    But, the answer is yes, you'd use a query (or series of queries) to get that
    information off the switch. You'd do best to familiarize yourself with the
    way that SNMP works. Either get a book, or search the resources on the web.
     
    Scooby, Apr 22, 2005
    #8
  9. ProgDario

    ProgDario Guest

    OK, I'll explaine the purpose of my application.

    I have two input parameters: [DHCP Server address] and [Some device MAC
    address].

    I have to write a Java class that retrieves the ARP table from a DHCP
    remote server by knowing its IP ADDRESS.

    Then, with the ARP TABLE listed, I have to extract the IP ADDRESS of a
    device by knowing the MAC Address.


    Thanks!!

    :)ario
     
    ProgDario, Apr 22, 2005
    #9
  10. ProgDario

    John Smith Guest

    "ProgDario" <> wrote in message
    news:...
    > Yes, it could be useful, but if I am on a PC, how can I grab the ARP
    > table on the DHCP SERVER that's on another PC?
    >
    > Thanks again!!
    >
    > :)ario
    >


    psexec from pstools would be able to do this.

    http://www.sysinternals.com/ntw2k/freeware/psexec.shtml
     
    John Smith, Apr 22, 2005
    #10
  11. ProgDario

    ProgDario Guest

    Thanks for the hint John Smith,

    but I think this is not what I need. My developer group discouraged me
    to use a command line executable. Someone suggested me to build an SNMP
    query, so I'm headed in this direction.

    If you have any hint..........

    :)ario
     
    ProgDario, Apr 22, 2005
    #11
  12. ProgDario

    John Smith Guest


    > but I think this is not what I need. My developer group discouraged me
    > to use a command line executable. Someone suggested me to build an SNMP
    > query, so I'm headed in this direction.
    >
    > If you have any hint..........
    >
    > :)ario
    >


    gottcha. sorry, no hints, that's the limit of my knowledge!
     
    John Smith, Apr 22, 2005
    #12
  13. In article <>,
    ProgDario <> wrote:
    :I have two input parameters: [DHCP Server address] and [Some device MAC
    :address].

    :I have to write a Java class that retrieves the ARP table from a DHCP
    :remote server by knowing its IP ADDRESS.

    :Then, with the ARP TABLE listed, I have to extract the IP ADDRESS of a
    :device by knowing the MAC Address.

    The DHCP server is not necessarily going to have still have the
    appropriate ARP entry in it's tables. DHCP tables are stored seperately
    than ARP tables. ARP tables are used to figure out how to communicate
    with a device, but if the host (or phone) does not happen to talk
    to the DHCP server for awhile, the ARP entry might time out.

    If you need to find the IP address even when the MAC might have
    been quiet for awhile, then you are going to have to find some way
    to query the DHCP server DHCP tables. That's not necessarily possible
    at all, and when possible might involve parsing HTML output or
    similar tedious chores in the general case. [I didn't look back to see
    whether there was a constraint on what the DHCP server is.]

    If the device is active, then you would likely find it easier to
    do some SNMP queries of the local [managed] router, rather than of the
    DHCP server.

    On a router-like device, you should snmpwalk the OID
    ..1.3.6.1.2.1.4.22.1.2
    and parse the outputs, which may look something like

    ..1.3.6.1.2.1.4.22.1.2.260.172.16.0.1 = 0:e0:16:99:1d:84

    Find the line that matches the MAC you are interested in. Note
    that different devices might or might not supress leading 0's
    in the MAC, and note that different devices might use a different
    delimiter such as - instead of : between the parts. Possibly
    some devices use uppercase instead of lower case, or use
    spaces between the parts (I haven't personally seen either of
    those cases for -this- OID, but both are common when look
    at a different OID for switches). The output could have ended with
    00-e0-16-99-1d-84 instead of 0:e0:16:99:1d:84
    so make sure that you know how your device transforms the MACs and
    adjust your search strategy accordingly.

    Once you have found the line that ends in the correct MAC, then
    the last 4 portions of the OID are the IP address -- 172.16.0.1
    in this example. The portion immediately before that, 260 in this
    example, is a location code. On some routers, this location code
    is an index to the VLAN table, and in other routers it encodes
    additional information. For example, on a Nortel Passport/Accelar 1200
    series, it encodes the module number, port number, and an index
    into a VLAN table. You may not care now about the location code, but
    when you are attempting to *find* the IP phone, you will find the
    location code to be an essential linkage.


    The general task of tracing down a MAC through a chain of devices
    is messy and often involves model-line specific code (especially
    for switches.)
    --
    "Mathematics? I speak it like a native." -- Spike Milligan
     
    Walter Roberson, Apr 22, 2005
    #13
  14. ProgDario

    Scooby Guest

    "ProgDario" <> wrote in message
    news:...
    > OK, I'll explaine the purpose of my application.
    >
    > I have two input parameters: [DHCP Server address] and [Some device MAC
    > address].
    >
    > I have to write a Java class that retrieves the ARP table from a DHCP
    > remote server by knowing its IP ADDRESS.
    >
    > Then, with the ARP TABLE listed, I have to extract the IP ADDRESS of a
    > device by knowing the MAC Address.
    >
    >
    > Thanks!!
    >
    > :)ario
    >


    That almost sounds like a school project. Remember, there is more than one
    way to skin a cat. If you have to follow the instructions as above, you may
    be SOL trying to get the arp table easliy from the PC based DHCP server -
    and as noted, it may not be up to date with all addresses. It can be done,
    it is just not trivial. However, as I mentioned, you may wish to use SNMP
    queries to the network devices. Not sure what classes are available for
    Java, but I would guess they are there.

    If you are up for it, you could write a service that would sit on the dhcp
    server. You query this service, it will ping the end device, read the arp
    table and send you back the mac address. That is probably the cleanest
    option, but more cumbersome to develop.

    Keep in mind that all of this assumes that the DHCP server is sitting on the
    same subnet as the phone. If not, you have other challenges.

    Another possibility would be to use an HTTP request to the phone itself.
    The Cisco phones have a web server built in. If you go to http://<address
    of phone>/ you will see a general info page. That page has the mac address.
    Do a little parsing of the page and you will have what you need.

    Jim
     
    Scooby, Apr 22, 2005
    #14
  15. ProgDario

    Majortom Guest

    Are you working in a CallManager environment? If so, you may notice that the
    IP address of the phone is displayed with a link to the phone's http server
    right on the phone configuration website. This would indicate that the
    ccm0300 database may contain the MAC or device name (SEP...) to IP mapping.
    A SQL query on the callmanager database might do the trick.

    Just a thought...
     
    Majortom, Apr 26, 2005
    #15
  16. ProgDario

    ProgDario Guest

    Thanks to all,

    it seems to me that the solution closer now......

    One question: how do I phisically construct the SNMP query and send it
    to the server?. How can I parse the result. Do I have to send it via
    socket or in another way?


    Thank!!


    ProgDario
     
    ProgDario, Apr 26, 2005
    #16
  17. In article <>,
    ProgDario <> wrote:
    :One question: how do I phisically construct the SNMP query and send it
    :to the server?. How can I parse the result. Do I have to send it via
    :socket or in another way?

    You don't seem to have read the Usage or example documents on the
    link I directed you to.
    --
    Entropy is the logarithm of probability -- Boltzmann
     
    Walter Roberson, Apr 26, 2005
    #17
  18. ProgDario

    ProgDario Guest

    I finally solved my problem.

    I used the free JAVA SNMP package. I used the MIB path
    1.3.6.1.2.1.4.22, corresponding to the ipNetToMediaTable, exactly what
    I was looking for.

    This is a part of the code I wrote:


    public static String SNMPMacToIp(String mac, String serverAddress,
    String community) {
    try {
    InetAddress hostAddress = InetAddress.getByName(serverAddress);
    SNMPv1CommunicationInterface comInterface =
    new SNMPv1CommunicationInterface(VERSION, hostAddress,
    community);
    java.util.Vector v = extractNetToMediaTable(comInterface);
    if (v == null) {
    return null;
    }
    return findIpAddress(mac, v);
    } catch (Exception e) {
    throw new RuntimeException("Exception during MIB search: " +
    e.getMessage(), e);
    }
    }


    private static String findIpAddress(String mac, java.util.Vector v) {
    SNMPSequence pair = null;
    SNMPObjectIdentifier snmpOID = null;
    SNMPObject snmpValue = null;
    int s = v.size();
    String result = null;
    for (int i = 0; i < s; i++) {
    pair = (SNMPSequence) (v.get(i));
    snmpValue = pair.getSNMPObjectAt(1);
    if
    (snmpValue.getClass().getName().equalsIgnoreCase("snmp.SNMPOctetString"))
    {
    String hexStr =
    ((SNMPOctetString)snmpValue).toHexString().trim();
    if (hexStr.equalsIgnoreCase(mac)) {
    snmpOID = (SNMPObjectIdentifier)pair.getSNMPObjectAt(0);
    OIDParser op = new OIDParser(snmpOID.toString());
    result = op.getIpAddress();
    break;
    }
    }
    }
    return result;
    }

    private static Vector
    extractNetToMediaTable(SNMPv1CommunicationInterface comInterface) {
    SNMPVarBindList newVars;
    try {
    newVars = comInterface.retrieveMIBTable(IP_NET_TO_MEDIA_TABLE);
    } catch (Exception e) {
    throw new RuntimeException("Errore in estrazione NTMTable: " +
    e.getMessage(), e);
    }
    return (java.util.Vector) (newVars.getValue());
    }
    }



    TNX to all!!

    :)ario






    Walter Roberson wrote:
    > In article <>,
    > ProgDario <> wrote:
    > :One question: how do I phisically construct the SNMP query and send

    it
    > :to the server?. How can I parse the result. Do I have to send it via
    > :socket or in another way?
    >
    > You don't seem to have read the Usage or example documents on the
    > link I directed you to.
    > --
    > Entropy is the logarithm of probability -- Boltzmann
     
    ProgDario, May 6, 2005
    #18
    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. Jerry West

    Obtaining IP address of all devices on network

    Jerry West, Jul 19, 2004, in forum: Wireless Networking
    Replies:
    4
    Views:
    176,720
    md seraj alam
    May 22, 2011
  2. Eric Logsdon

    Obtaining IP Address via DHCP

    Eric Logsdon, Oct 25, 2005, in forum: Wireless Networking
    Replies:
    0
    Views:
    623
    Eric Logsdon
    Oct 25, 2005
  3. Madhu
    Replies:
    1
    Views:
    676
  4. =?Utf-8?B?U3dhbGx5?=

    Wireless Laptop obtaining IP address but not allowed to get on Int

    =?Utf-8?B?U3dhbGx5?=, Nov 10, 2006, in forum: Wireless Networking
    Replies:
    2
    Views:
    834
    =?Utf-8?B?U3dhbGx5?=
    Nov 11, 2006
  5. ttripp
    Replies:
    5
    Views:
    2,270
    Thrill5
    Feb 5, 2010
Loading...

Share This Page