网络信息收集脚本详解

网络信息收集脚本

目的

该PowerShell脚本从系统收集网络信息,用于监控和故障排除。它获取网络适配器详细信息、IP配置、DNS配置和路由表。

前提条件

  • Windows PowerShell 5.1 或更高版本
  • 运行PowerShell脚本的管理员权限

使用方法

  1. 使用管理员权限打开Windows PowerShell
  2. 导航到包含脚本的目录
  3. 使用以下命令运行脚本:
    .\NetworkInformation.ps1
    

脚本描述

  • 脚本使用各种与网络相关的PowerShell cmdlet收集信息
  • 它获取网络适配器详细信息、IP配置、DNS配置和路由表
  • 收集的信息以格式化表格形式显示,便于阅读

脚本内容

# 获取网络适配器信息
$networkAdapters = Get-NetAdapter | Select-Object -Property Name, InterfaceDescription, MacAddress, LinkSpeed, Status

# 获取IP配置
$ipConfig = Get-NetIPAddress | Where-Object { $_.InterfaceAlias -ne "Loopback Pseudo-Interface 1" } | Select-Object -Property InterfaceAlias, IPAddress, PrefixLength, AddressFamily

# 获取DNS配置
$dnsConfig = Get-DnsClientServerAddress | Where-Object { $_.InterfaceAlias -ne "Loopback Pseudo-Interface 1" } | Select-Object -Property InterfaceAlias, ServerAddresses

# 获取路由表
$routeTable = Get-NetRoute | Where-Object { $_.DestinationPrefix -ne "0.0.0.0/0" } | Select-Object -Property DestinationPrefix, NextHop, RouteMetric

# 显示网络适配器信息
Write-Host "Network Adapters:"
$networkAdapters | Format-Table -AutoSize

# 显示IP配置
Write-Host "`nIP Configuration:"
$ipConfig | Format-Table -AutoSize

# 显示DNS配置
Write-Host "`nDNS Configuration:"
$dnsConfig | Format-Table -AutoSize

# 显示路由表
Write-Host "`nRouting Table:"
$routeTable | Format-Table -AutoSize

输出

脚本输出包含收集到的网络信息的格式化表格。

注意事项

  • 该脚本适用于Windows系统
  • 确保以管理员权限运行脚本以访问所有必需的网络信息
  • 根据需要自定义脚本以包含其他网络详细信息或过滤条件

本文档全面概述了脚本的目的、前提条件、使用说明、脚本内容描述、预期输出和用户的其他注意事项。可以根据特定的组织要求或偏好进行调整。
更多精彩内容 请关注我的个人公众号 公众号(办公AI智能小助手)
公众号二维码

posted @ 2025-09-06 16:18  qife  阅读(10)  评论(0)    收藏  举报