How to find all the snmp enabled devices in my network ?
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to find all the snmp enabled devices in my network ?
Hi
I want to find all the snmp enabled devices in my network, I got something like how it works in a agent and manager architecture.
I got net-snmp library to create a simple application to get the snmp data from a remote device.I have to write a program to do this ,I want the mac address of the device and some more info.
What is oid for getting mac and what is the oid of getting all the system info of the snmp enabled devices.
But ,can any one tell some more information about this .
I got some idea like,I have to broadcast a message and the snmp enabled device will respond to this with some information what I want to get from that device.
Kindly tell me something ,broad cast means ,I have to send the snmp request to the boradcast IP of my network ,Is this correct ?
Kindly tell something about this.
Thanks
Last edited by pradiptart; 08-09-2012 at 07:38 AM.
Hi
I want to find all the snmp enabled devices in my network, I got something like how it works in a agent and manager architecture. I got net-snmp library to create a simple application to get the snmp data from a remote device.I have to write a program to do this ,I want the mac address of the device and some more info.
What is oid for getting mac and what is the oid of getting all the system info of the snmp enabled devices.
There is no OID for a MAC address...devices return whatever information they have, for the OID's they have loaded. The OID for a Cisco switch will be different than that for a laptop, than for a desktop, etc.
Quote:
But ,can any one tell some more information about this .
I got some idea like,I have to broadcast a message and the snmp enabled device will respond to this with some information what I want to get from that device.
Kindly tell me something ,broad cast means ,I have to send the snmp request to the boradcast IP of my network ,Is this correct ?
You've asked several questions about doing such network-discovery type things, such as using NMAP and ping. Now this...it's starting to sound a bit suspicious, in my opinion.
Since you have the Net::SNMP perl module, you know about CPAN...which can lead you to the Net::SNMP::QueryEngine module, and the Net::MAC module too. Both of which do things you might need. Writing a program to take a beginning and ending address ranges to cycle through them and do an SNMP query should be fairly simple..what have you done/tried so far? You can also use snmpwalk/snmpget in a bash script with looping to do the same things.
You've asked several questions about doing such network-discovery type things, such as using NMAP and ping. Now this...it's starting to sound a bit suspicious, in my opinion.
It makes me laugh ,ha ha ha.but I am not a hacker till now .It is a requirement for my project to discover devices.
We are not using any third party solution to discover devices instead we are developing products to do so.
As nmap is free tool we cant use this in our product to sell that thing.
following is a shell script I have written but it using a nmap so It is not useful for me.Now my idea is to use snmp and discover the network devices .
Code:
#!/bin/sh
if [ $# -ne 1 ];then
echo -e "\e[0;31m Usage :"
echo "./scanx.sh <IP> "
echo "./scnaX 10.0.0.3 :-> To get details of only one IP "
echo "./scanX 10.0.0.3-10 :-> To get details of a range of IP from 3 to 10"
echo -n -e "\e[0;0m"
exit
fi
v_ip=$1
flag=0
mac_manu1=""
counter=0
ip=""
mac=""
mac3=""
cname=""
netdis=""
man_manu=""
os=""
ismsos=""
devicetype=""
isprinter=""
#function to convert upper case
toUpper()
{
echo $1 | tr "[:lower:]" "[:upper:]"
}
#function to search ite out.txt
searchOui()
{
#get the mac upto 24 bit
mac3=`echo "$mac" | awk -F: '{print $1"-"$2"-"$3}'`
#get the manufaturer name from oui file ,get only the first value separated by , and skip all the () characters
mac_com=`cat oui.txt | grep $mac3 | awk -F ' ' '{print $3,$4,$5,$6,$7}'| sed 's/(//g' | sed 's/)//g'| awk -F , '{print $1}'`
#assing with the variable
if [ "$mac_com" != "" ];then
mac_manu=$mac_com
else
mac_manu=""
fi
}
#check for phone or not
isPhoneChk()
{
while read pname
do
if [ `toUpper $pname` == `toUpper $1` ];then
flag=1
#once matched then no need to loop again
break
else
flag=0
fi
done <fcname
}
#parsing the scan result
parsescan()
{
#get the file and parse
#read the content of the file one line by line
while read readl
do
#if end of one scan then print all value
start_point=`echo $readl | grep "Nmap scan report for"`
if [ "$start_point" != "" ]; then
counter=`expr $counter + 1 `
fi
#check for the ip
ipp=`echo $readl | grep "Nmap scan report" | awk -F ' ' '{print $6}' | sed 's/(//g' | sed 's/)//g'`
if [ "$ipp" != "" ];then
ip=$ipp
fi
#check for mac address and manufacture
macc=`echo $readl | grep MAC | awk -F ' ' '{print $3}'`
if [ "$macc" != "" ];then
mac=$macc
fi
#check for the computer name
ccname=`echo $readl | grep "Nmap scan report" | awk -F ' ' '{print $5}'`
if [ "$ccname" != "" ];then
cname=$ccname
fi
#check for the manufature of mac
mac_manuu=`echo $readl | grep MAC | awk -F ' ' '{print $4,$5,$6,$7,$8}' | sed 's/(//g' | sed 's/)//g'`
if [ "$mac_manuu" != "" ];then
#find for the unknown type of company name and get it from oui.txt file
searchOui $mac_manuu
#for detecting phone company
mac_manu1=`echo $mac_manu | awk -F ' ' '{print $1}'`
fi
#check os
oss=`echo $readl | grep "OS details" | awk -F: '{print $2}' | awk -F , '{print $1}'`
if [ "$oss" != "" ];then
os=$oss
fi
#check the last line
netdiss=`echo $readl | grep "Network Distance:"`
if [ "$netdiss" != "" ];then
netdis=$netdiss
fi
#check for the device type
devicetypee=`echo $readl | grep "Device type:" | awk -F: '{print $2}'`
if [ "$devicetypee" != "" ];then
devicetype=$devicetypee
fi
#check for the printer of HP
isprinterr=`echo $readl | grep "9100/tcp" | awk -F ' ' '{print $3}'`
if [ "$isprinterr" != "" ];then
isprinter=$isprinterr
fi
#check for the microsoft os
ismsoss=`echo $readl | grep "445/tcp" | awk -F ' ' '{print $3}'`
if [ "$ismsoss" != "" ];then
ismsos=$ismsoss
fi
#printing all the values
if [ "$netdis" != "" ]; then
#print all values
echo -e "\t -----------------------------------------------"
echo -e "\t "$counter
if [ "$ip" != "" ];then
echo -e "\t IP : "$ip
fi
if [ "$mac" != "" ];then
echo -e "\t MAC : "$mac
fi
if [ "$mac_manu" != "" ];then
echo -e "\t MAC manufacturer : "$mac_manu
#check for mobile phone
isPhoneChk $mac_manu1
if [ $flag -eq 1 ];then
echo -e "\t Device type : Phone"
else
if [ "$devicetype" != "" ];then
echo -e "\t Device type :"$devicetype
fi
fi
fi
if [ "$cname" != "" ];then
echo -e "\t Device name : "$cname
fi
if [ "$os" != "" ];then
echo -e "\t OS : "$os
fi
if [ "$isprinter" != "" ];then
echo -e "\t port 9100 service : "$isprinter
fi
#after printing set all the variables to the default value
ip=""
mac=""
cname=""
netdis=""
man_manuu=""
os=""
devicetype=""
isprinter=""
fi
#set network discovery string to "" to avoid printing values repeatadly
netdis=""
done < os
#log messeges
echo -e "\e[35m \n Total no of device successfully scaned by scanX : $counter \e[0m"
#rm -f os
}
#disply
echo -e "\e[35m scanX started wait for the scan result....\e[0m"
#use nmap and store it in a file
nmap -O --osscan-guess -T3 $v_ip > os
#After nmap completes it takes few seconds to parse so give a message to user
echo -e "\e[35m Results in few seconds......\e[0m"
#parse it and show the result and store the result in a file
parsescan
Now using snmp tools snmpwalk I am getting may information but among which I want some system info,mac ,os name if avilable ,
but I how to program using net-snmp to get these info as I do not know the generic oid by which system name will come.I want to write a program and I have to get some required info so I need the oid ,I have to give this oid to the net-Snmp's function so that it will give me the coresponding result .
I have to use the string name like sysName to get the system name ,If so then in case of mac address there written "ifPhysAddress.2" and then the mac is mentioned (in the result of snmpwalk).so what is the oid to get the mac as it is different for all the device.
when I am using snmpwalk I am getting one line as follow
Quote:
SNMPv2-SMI::mib-2.25.3.2.1.3.1 = STRING: "HP LaserJet Professional P1606dn"
This is the name of the printer .means this oid is for getting the name of the printer (mib-2.25.3.2.1.3.1).
Is this true for all the device means if i query to this oid I will get the device name of the corresponding IP .Is this correct or not.
Kindly,give some idea.
Thanks
Last edited by pradiptart; 08-10-2012 at 03:38 AM.
Hi TB0ne Thanks for your reply,
It makes me laugh ,ha ha ha.but I am not a hacker till now .It is a requirement for my project to discover devices.
Well, no one else here is laughing. We do not know WHAT your intentions are, or what you need this information for, or what your 'project' is.
Quote:
We are not using any third party solution to discover devices instead we are developing products to do so. As nmap is free tool we cant use this in our product to sell that thing.
following is a shell script I have written but it using a nmap so It is not useful for me.Now my idea is to use snmp and discover the network devices .
Now using snmp tools snmpwalk I am getting may information but among which I want some system info,mac ,os name if avilable, but I how to program using net-snmp to get these info as I do not know the generic oid by which system name will come.I want to write a program and I have to get some required info so I need the oid ,I have to give this oid to the net-Snmp's function so that it will give me the coresponding result .
I have to use the string name like sysName to get the system name ,If so then in case of mac address there written "ifPhysAddress.2" and then the mac is mentioned (in the result of snmpwalk).so what is the oid to get the mac as it is different for all the device. when I am using snmpwalk I am getting one line as follow
This is the name of the printer .means this oid is for getting the name of the printer (mib-2.25.3.2.1.3.1). Is this true for all the device means if i query to this oid I will get the device name of the corresponding IP .Is this correct or not.
I did give you 'some idea', but you didn't take it. Again, OID's are different for EVERY DEVICE. There are SOME that are consistent between devices, but they return general information. If it's your 'project' to write a program, use Perl and the Net::SNMP modules, and (as said before), loop through all the addresses in a range, query them, and find out if they have SNMP installed or not, and you can then drill down to those devices more deeply from there.
If you want to 'sell that thing' without using other tools, then you will have to write your own. Go to http://www.cpan.org, and look up the modules I mentioned previously. Read the instructions, see the samples, and make use of them. Use another language/modules if you want...that's up to you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.