LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-08-2012, 07:47 AM   #1
pradiptart
Member
 
Registered: Sep 2007
Posts: 102

Rep: Reputation: 12
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.
 
Old 08-09-2012, 05:23 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by pradiptart View Post
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 .
Yes...http://www.google.com LOTS of information there for you
Quote:
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.
 
1 members found this post helpful.
Old 08-10-2012, 12:24 AM   #3
pradiptart
Member
 
Registered: Sep 2007
Posts: 102

Original Poster
Rep: Reputation: 12
Hi TB0ne Thanks for your reply,

Quote:
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.
 
Old 08-10-2012, 10:08 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by pradiptart View Post
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.

Last edited by TB0ne; 08-10-2012 at 10:50 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How To Simulate Network Devices Using SNMP Simulator LXer Syndicated Linux News 0 04-16-2012 09:00 AM
network-manager can't find my wireless devices asimov Ubuntu 4 09-27-2007 09:48 AM
Urgent : How to find whether the Network Interface is DHCP enabled or not ? abha_shrimal Linux - Networking 3 12-15-2005 01:50 PM
Cannot find wlan0 in network devices sublyme718 Linux - Wireless Networking 2 11-06-2005 07:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration