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


    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

    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

    Any hint is appreciated.

    Thanks in advance!!

    ProgDario, Apr 22, 2005
    1. Advertisements

  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.

    John Smith, Apr 22, 2005
    1. Advertisements

  3. ProgDario

    ProgDario Guest

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

    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?


    ProgDario, Apr 22, 2005
  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
    John Smith, Apr 22, 2005
  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!!

    ProgDario, Apr 22, 2005
  6. ProgDario

    Scooby Guest

    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

    Hope that helps,

    Scooby, Apr 22, 2005
  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?


    ProgDario, Apr 22, 2005
  8. ProgDario

    Scooby Guest

    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
  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

    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.


    ProgDario, Apr 22, 2005
  10. ProgDario

    John Smith Guest

    psexec from pstools would be able to do this.

    John Smith, Apr 22, 2005
  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..........

    ProgDario, Apr 22, 2005
  12. ProgDario

    John Smith Guest

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

    :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
    and parse the outputs, which may look something like

    .. = 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 --
    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.)
    Walter Roberson, Apr 22, 2005
  14. ProgDario

    Scooby Guest

    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.

    Scooby, Apr 22, 2005
  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
  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?


    ProgDario, Apr 26, 2005
  17. :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.
    Walter Roberson, Apr 26, 2005
  18. ProgDario

    ProgDario Guest

    I finally solved my problem.

    I used the free JAVA SNMP package. I used the MIB path, 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,
    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);
    String hexStr =
    if (hexStr.equalsIgnoreCase(mac)) {
    snmpOID = (SNMPObjectIdentifier)pair.getSNMPObjectAt(0);
    OIDParser op = new OIDParser(snmpOID.toString());
    result = op.getIpAddress();
    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!!

    ProgDario, May 6, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.