- Community Home
- >
- Networking
- >
- Legacy
- >
- Switches, Hubs, Modems
- >
- Find a port number from a MAC address using SNMP
Switches, Hubs, and Modems
1820484
Members
2263
Online
109624
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-24-2006 11:34 PM
тАО10-24-2006 11:34 PM
Find a port number from a MAC address using SNMP
Hi folks.
I'm writing a little bash shell script to find which port is connected an computer using snmp and its MAC.
I actually have some OID's to do it, but they only works in CISCO switches, they don't work with two HP J4899B ProCurve Switch 2650.
Has anyone any idea?
Thanks,
Sergio
I'm writing a little bash shell script to find which port is connected an computer using snmp and its MAC.
I actually have some OID's to do it, but they only works in CISCO switches, they don't work with two HP J4899B ProCurve Switch 2650.
Has anyone any idea?
Thanks,
Sergio
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-25-2006 10:39 PM
тАО10-25-2006 10:39 PM
Re: Find a port number from a MAC address using SNMP
You should use the BRIDGE-MIB for that, which is a standard MIB supported by almost anything.
The OID for the port o a MAC address is 1.3.6.1.2.1.17.4.3.1.1, so you can do:
snmpwalk sw2524-1 .1.3.6.1.2.1.17.4.3.1.2
SNMPv2-SMI::mib-2.17.4.3.1.2.0.0.116.117.96.246 = INTEGER: 11
SNMPv2-SMI::mib-2.17.4.3.1.2.0.1.230.133.83.224 = INTEGER: 26
SNMPv2-SMI::mib-2.17.4.3.1.2.0.4.118.248.42.33 = INTEGER: 26
... and so on
The MAC address is encoded in six decimal labels in the instance, so
0.0.116.117.96.246
really means 00:00:74:75:60:F6
Doing that in a shell script can be tricy: you are probably going to use cut and bc.
Regards,
Bergonz
The OID for the port o a MAC address is 1.3.6.1.2.1.17.4.3.1.1, so you can do:
snmpwalk sw2524-1 .1.3.6.1.2.1.17.4.3.1.2
SNMPv2-SMI::mib-2.17.4.3.1.2.0.0.116.117.96.246 = INTEGER: 11
SNMPv2-SMI::mib-2.17.4.3.1.2.0.1.230.133.83.224 = INTEGER: 26
SNMPv2-SMI::mib-2.17.4.3.1.2.0.4.118.248.42.33 = INTEGER: 26
... and so on
The MAC address is encoded in six decimal labels in the instance, so
0.0.116.117.96.246
really means 00:00:74:75:60:F6
Doing that in a shell script can be tricy: you are probably going to use cut and bc.
Regards,
Bergonz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-26-2006 04:51 AM
тАО10-26-2006 04:51 AM
Re: Find a port number from a MAC address using SNMP
That's my function... it worked like in CISCO but i didn't realized.
function busca_en_router {
ip=$1
first=`snmpwalk -v 1 -Os $ip -c .1.3.6.1.2.1.17.4.3.1.1 | grep "$mac" | cut -d= -f 1 | cut -d. -f 7-`
if [ -n "$first" ]; then
Bridge=`snmpwalk -v 1 -Os $ip -c .1.3.6.1.2.1.17.4.3.1.2.$first | cut -d" " -f4`
ifIndex=`snmpwalk -v 1 -Os $ip -c .1.3.6.1.2.1.17.1.4.1.2.$Bridge | cut -d" " -f4`
ifName=`snmpwalk -v 1 -Os $ip -c .1.3.6.1.2.1.31.1.1.1.1.$ifIndex | cut -d" " -f4`
echo $equipo" "`echo $mac | tr -s " " ":"`" "$ip" "$ifName
fi
}
Call it this way:
busca_en_router "00 11 22 33 44 55 66"
Of course you have to change it and put down your community, your own ip, and your version (!!!).
And if you don't want to see as a result if the pc is attached to a gigabyte port (because it is really attached to a fastethernet port in other switch connected via this gigabyte port), add this "if" before the "echo", and the "fi" after, like that:
if [ "$ifName" != "Gi0/1" ] && [ "$ifName" != "Gi0/2" ]; then
echo $equipo" "`echo $mac | tr -s " " ":"`" "$ip" "$ifName
fi
It has helped me a lot to make a fast "net map" of my computers and switches.
And I'm sure it can be writed better... but works ;)
Thanks a lot!
function busca_en_router {
ip=$1
first=`snmpwalk -v 1 -Os $ip -c
if [ -n "$first" ]; then
Bridge=`snmpwalk -v 1 -Os $ip -c
ifIndex=`snmpwalk -v 1 -Os $ip -c
ifName=`snmpwalk -v 1 -Os $ip -c
echo $equipo" "`echo $mac | tr -s " " ":"`" "$ip" "$ifName
fi
}
Call it this way:
busca_en_router
Of course you have to change it and put down your community, your own ip, and your version (!!!).
And if you don't want to see as a result if the pc is attached to a gigabyte port (because it is really attached to a fastethernet port in other switch connected via this gigabyte port), add this "if" before the "echo", and the "fi" after, like that:
if [ "$ifName" != "Gi0/1" ] && [ "$ifName" != "Gi0/2" ]; then
echo $equipo" "`echo $mac | tr -s " " ":"`" "$ip" "$ifName
fi
It has helped me a lot to make a fast "net map" of my computers and switches.
And I'm sure it can be writed better... but works ;)
Thanks a lot!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-26-2006 04:53 AM
тАО10-26-2006 04:53 AM
Re: Find a port number from a MAC address using SNMP
I have a typo... sorry.
Add mac=$2 after ip=$1 ....
Add mac=$2 after ip=$1 ....
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP