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

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

Reply to
ProgDario
Loading thread data ...

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

Reply to
John Smith

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

Reply to
ProgDario

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

Reply to
John Smith

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

Reply to
ProgDario

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

Reply to
Scooby

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

Reply to
ProgDario

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.

Reply to
Scooby

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

Reply to
ProgDario

psexec from pstools would be able to do this.

formatting link

Reply to
John Smith

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

Reply to
ProgDario

gottcha. sorry, no hints, that's the limit of my knowledge!

Reply to
John Smith

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

Reply to
Walter Roberson

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

Reply to
Scooby

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

Reply to
Majortom

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

Reply to
ProgDario

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.

Reply to
Walter Roberson

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, corresp 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 Robers> > :One question: how do I phisically construct the SNMP query and send it

Reply to
ProgDario

Cabling-Design.com Forums website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.