我试图自动化Paketbeat安装,但Windows上所需要的一件事是您需要找到活动网络适配器的设备ID。
可以使用.\packetbeat devices
查询设备列表。
示例输出是:
PS C:\Program Files\packetbeat> .\packetbeat.exe devices 0: \Device\NPF_NdisWanIp (NdisWan Adapter) (Not assigned ip address) 1: \Device\NPF_NdisWanBh (NdisWan Adapter) (Not assigned ip address) 2: \Device\NPF_{DD2F4800-0DEB-4A98-A302-0777CB955DC1} (AsyncMac Adapter) (Not assigned ip address) 3: \Device\NPF_NdisWanIpv6 (NdisWan Adapter) (Not assigned ip address) 4: \Device\NPF_{5B8B7F6A-EF39-4D95-A3A5-4BF70077E936} (VMware vmxnet3 virtual network device) (12.54.26.105) 5: \Device\NPF_{B8522370-3DA7-4F29-91FC-0718181D5661} (MS LoopBack Driver) (0.0.0.0)
在上面的用例中,我需要检索4
。
或
PS C:\Program Files\packetbeat> .\packetbeat.exe devices 0: \Device\NPF_NdisWanIp (NdisWan Adapter) (Not assigned ip address) 1: \Device\NPF_NdisWanBh (NdisWan Adapter) (Not assigned ip address) 2: \Device\NPF_{DD2F4800-0DEB-4A98-A302-0777CB955DC1} (AsyncMac Adapter) (Not assigned ip address) 3: \Device\NPF_{8E8A32C0-6E4D-46ED-9723-9D656A26D1F5} (EMULEX) (12.54.18.145) 4: \Device\NPF_NdisWanIpv6 (NdisWan Adapter) (Not assigned ip address) 5: \Device\NPF_{83485D06-422D-4558-AC88-5D0EB800BB1C} (MS LoopBack Driver) (fe80::ezeb:459b:61a4:c175 0.0.0.0) PS C:\Program Files\packetbeat> .\packetbeat.exe devices | Select-Object
在上面的用例中,我需要检索3
。我很乐意根据设备ID找到使用PowerShell的ID,该ID具有以12.45
开头配置的IP。
答案 0 :(得分:1)
使用-match
运算符过滤以匹配的IP地址结尾的行的输出,然后将该行拆分为冒号并从结果数组中选择第一个元素:
((packetbeat.exe devices) -match '\(12\.54\.\d+\.\d+\)$' -split ':')[0]