我正在尝试使用以下代码从过滤后的JSON中提取IP:
$curl = Invoke-WebRequest -Method Get -Uri "http://urltojson.com/file.json"
$curl2 = $curl.Content.Replace("Script", "Script_").Replace("iphone", "iphone_").Replace("android", "android_").Replace("ipad","ipad_") |
ConvertFrom-Json
$curl3 = $curl2 | Where-Object {$_.Name -eq "/Common/cloudfront_nets"} |
Select-Object -ExpandProperty data
$curl3
[System.Collections.ArrayList]$curl3[0] = $curl3
$curl3[1]
返回以下内容
13.59.250.0 255.255.255.192 : region: us-east-2-service: CLOUDFRONT 52.57.254.0 255.255.255.0 : region: eu-central-1-service: CLOUDFRONT 54.182.0.0 255.255.0.0 : region: GLOBAL-service: CLOUDFRONT 52.212.248.0 255.255.255.192 : region: eu-west-1-service: CLOUDFRONT 205.251.250.0 255.255.254.0 : region: GLOBAL-service: CLOUDFRONT 35.162.63.192 255.255.255.192 : region: us-west-2-service: CLOUDFRONT 13.32.0.0 255.254.0.0 : region: GLOBAL-service: CLOUDFRONT 205.251.254.0 255.255.255.0 : region: GLOBAL-service: CLOUDFRONT
我很难简单地输出IP(没有子网掩码)。
有人可以帮忙吗?
答案 0 :(得分:0)
您可以使用$myArray -split
拆分空格上的最后$curl3[1]
,然后只选择第一个数组值。
例如,($curl3[1] -split " ")[0]
只会为您提供该字符串中的IP地址。