XOS run python scripts v15.7 or high
將交換器上的 IP & MAC 往syslog 丟, 簡單將IP資料保留下
## 編緝Scripts
# vi ip2syslog.py
#!/usr/bin/python
# Client program
import sys
import io
from socket import *
f = open('/proc/self/ns_id', 'w')
f.write('2\n') #VR-DEFAUTL
f.close()
exsh.clicmd('disable clipaging', False)
# Set the socket parameters
host = "192.168.254.10"
port = 514
buf = 1024
addr = (host,port)
# Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM)
cnt = 0
for line in exsh.clicmd('show iparp', True).splitlines():
tokens = line.split()
if len(tokens) == 0:
continue
if len(tokens) == 8:
if tokens[2][0].isdigit():
oui = tokens[2].lower()[:8]
if oui:
UDPSock.sendto('MAC:'+tokens[2]+' IP:'+tokens[1]+' port:'+tokens[-1], addr)
cnt += 1
UDPSock.close()
## 執行scripts
# run scripts ip2syslog.py
## 收到LOG ...
Nov 28 03:26:56 10.100.3.145 MAC: 74:3e:cb:10:21:89 IP:192.168.1.221 port:15
Nov 28 03:26:56 10.100.3.145 MAC: 78:44:76:d6:5c:b9 IP:192.168.1.232 port:23
Nov 28 03:26:56 10.100.3.145 MAC: 74:3e:cb:10:27:4d IP:192.168.1.234 port:18
Nov 28 03:26:56 10.100.3.145 MAC: 74:3e:cb:10:22:2f IP:192.168.1.236 port:5
Nov 28 03:26:56 10.100.3.145 MAC: 74:3e:cb:10:27:49 IP:192.168.1.238 port:11
Nov 28 03:26:56 10.100.3.145 MAC: 74:3e:cb:10:27:45 IP:192.168.1.241 port:7
Nov 28 03:26:56 10.100.3.145 MAC: 00:d0:41:d8:cb:fd IP:192.168.1.242 port:23
Nov 28 03:26:56 10.100.3.145 MAC: 74:3e:cb:10:22:2b IP:192.168.1.244 port:10
Nov 28 03:26:56 10.100.3.145 MAC: 74:3e:cb:10:22:29 IP:192.168.1.245 port:12
Nov 28 03:26:56 10.100.3.145 MAC: 00:11:32:49:5e:7f IP:192.168.1.252 port:4
...
...
...
##在搭 upm 排程執行, 就可以簡單記錄IP & MAC
沒有留言:
張貼留言