Operating System - Linux
1820160 Members
2812 Online
109620 Solutions
New Discussion юеВ

Re: snmpget result and ip name on the same row

 
Alpha977
Valued Contributor

snmpget result and ip name on the same row

Hello to all!

I need a command to show the nodename and ip address on the same row, example of result:

system.sysName.0 : DISPLAY STRING- (ascii): MANROUTER9 192.168.0.1

I think something like this:
snmpget -c public 192.168.0.1 system.sysName.0 |echo "192.168.0.1"

but don't work.

Thanks to all

Points for all reply
6 REPLIES 6
Court Campbell
Honored Contributor

Re: snmpget result and ip name on the same row

It's ugly but it works.

snmpget -c public -v 1 192.168.0.1 system.sysName.0 | awk '{print $0, "#", $4}' | perl -MSocket -ne '($snmp, $host) = split (/#/, $_); $host =~ s/^\s+|\s+$//g; print $snmp; print inet_ntoa(scalar gethostbyname($host));'
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Alpha977
Valued Contributor

Re: snmpget result and ip name on the same row

Thanks for reply, but don't work to me.
Court Campbell
Honored Contributor

Re: snmpget result and ip name on the same row

What is the error you get?
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Alpha977
Valued Contributor

Re: snmpget result and ip name on the same row

Hello!

Don't appear anything.
Remain in wait status.

thks
Court Campbell
Honored Contributor

Re: snmpget result and ip name on the same row

does this return anything:

snmpget -c public -v 1 192.168.0.1 system.sysName.0

if so see if this works:

snmpget -c public -v 1 192.168.0.1 system.sysName.0 | awk '{print $0, "#", $4}'

Let me know and we can work from there. Maybe you left of the trailing '.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Alpha977
Valued Contributor

Re: snmpget result and ip name on the same row

Hello to all!

I have created this.
This scan all the 192.168.1.xxx subnet and output a file with "hostname ipaddress".
I hope this helpful for someone!

i=1
while [[ ${i} -lt 255 ]]
do
export IP="192.168.1.${i}"
snmpget -c public -t 1 -r 0 ${IP} system.sysName.0 2> /dev/null | awk '{ print $6 }' |while read a
do
echo $a $IP >> nodes.txt
done