dickrong 发表于 2018-9-2 11:07:08

PowerShell统计本地的网络连接(CMD吐数据互访)

#Powered By kukisama   http://jiushu.blog.51cto.com/  
netstat -an |Out-FileD:\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 "protolocal 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


页: [1]
查看完整版本: PowerShell统计本地的网络连接(CMD吐数据互访)