|
#Powered By kukisama http://jiushu.blog.51cto.com/
netstat -an |Out-File D:\3456.csv
$files = (Get-Childitem d:\3456.csv).pspath
$content = get-content $files
clear-content $files
add-Content $files -Value "proto,localAddress,duankou,duiduanip,duiduanduanou,zhuangtai"
foreach ($line in $content -ne "active connections" -ne " proto local address foreign address state" -ne "活动连接" -ne " 协议 本地地址 外部地址 状态")
{
$liner = $line.Replace("[::1]","local");
$line = $liner
$liner = $line.Replace("[::]","local");
$line = $liner
$line = $liner -replace("\s{1,}" ,",")
$liner = $line
$line = $liner -replace(":{1,}" ," ")
$liner = $line
$liner = $line.Replace(",TCP","TCP")
$line = $liner
$liner = $line.Replace(",UDP","UDP")
$line = $liner
$line = $liner -replace("\s{1,}" ,",")
$liner = $line
$liner = $line.Replace("127.0.0.1","local")
$line = $liner
$liner = $line.Replace("0.0.0.0","local")
$line = $liner
add-Content $files -Value $liner
}
$files
$bb = Import-Csv -Path d:\3456.csv
echo "====================================="
echo "以下为协议计数"
$bb| Group-Object –Property:proto|select Name,Count|sort -Property count
echo "====================================="
echo "以下为您本地IP连接外端地址的统计数据"
$bb| Group-Object –Property:localAddress|select Name,Count|sort -Property count
echo "====================================="
echo "以下为外端地址连接您本地IP的统计数据"
$bb| Group-Object –Property:duiduanip|select Name,Count|sort -Property count
echo "====================================="
echo "以下为状态计数"
$bb| Group-Object –Property:zhuangtai|select Name,Count|sort -Property count
|
|
|