使用nmap掃描主機,並使用Shell Script與Python自動將IP、MAC與網卡廠商加入Mysql

Step1)使用shell script與nmap掃描主機,呼叫Step2的nmap-ip.py分析nmap結果與新增到資料庫。

#!/bin/sh

hosts="192.168.0.1/24"

basedir="/usr/home/nmap"

mytime=`/bin/date +%Y%m%d%H%M`

cd $basedir

nmap -sn -n $hosts > nmap-$mytime

python nmap-ip.py nmap-${mytime}

Step2)使用Python分析nmap掃描結果並加入資料庫,檔案命名為nmap-ip.py,Step1所產生的nmap-$mytime檔案。