#!/local/bin/tclnm

# search arp-cache, optionally match regexp.

if {$argc != 3 && $argc != 2} {
    puts stderr "Usage:\n\t[lindex $argv 0] hostname \[regexp\]" 
    exit 2
}

set s0 [snmp open [lindex $argv 1]]

snmp getbulk $s0 { at.atTable.atEntry.atPhysAddress } v {
    set ip [join [lrange [split [lindex $v 0] .] 13 end] .]
    set eth [lindex $v 2]
    if {$argc == 3} {
	if {[regexp [lindex $argv 2] "$eth $ip"]} {
	    puts stdout "$eth $ip"
	}
    } else {
	puts stdout "$eth $ip"
    }
}
