Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json Powerhsell-需要解决IP问题_Json_Powershell_Dns_Ip_Fqdn - Fatal编程技术网

Json Powerhsell-需要解决IP问题

Json Powerhsell-需要解决IP问题,json,powershell,dns,ip,fqdn,Json,Powershell,Dns,Ip,Fqdn,我可以将包含原始数据的文件导出为json、xml或csv。我选择了JSON JSON输出如下所示 { "entry":[{ "@name":"31.170.162.203", "ip-netmask": "31.170.162.203", "description": "test1"} , { "@name":"37.193.217.222", "ip-netmask": "37.193.217.222", "description": "test2"} , { "@name":"46.17.6

我可以将包含原始数据的文件导出为json、xml或csv。我选择了JSON

JSON输出如下所示

{
"entry":[{
"@name":"31.170.162.203",
"ip-netmask":
"31.170.162.203",
"description":
"test1"}
,
{
"@name":"37.193.217.222",
"ip-netmask":
"37.193.217.222",
"description":
"test2"}
,
{
"@name":"46.17.63.169",
"ip-netmask":
"46.17.63.169",
"description":
"test3"}
,
]
}

输出:

31.170.165.68
31.170.162.203
l37-193-217-222.novotelecom.ru
这告诉我它正在替换已解析的IP,并保留所有未解析的原始IP。这正是我想要的

我最终通过进一步的研究、尝试和错误找到了解决方法。

事情1- 发布的json格式不正确

事情2-

读入json字符串、csv、xml文件数据,并将IPA传递给.Net类或DNS cmdlet以解析它们

一个例子(还有其他方法)

还是这样

(@'
{
"entry":[{
"@name":"31.170.162.203",
"ip-netmask":"31.170.162.203",
"description":"test1"}
,
{
"@name":"37.193.217.222",
"ip-netmask":"37.193.217.222",
"description":"test2"}
,
{
"@name":"46.17.63.169",
"ip-netmask":"46.17.63.169",
"description":"test3"}
]
}
'@ | 
ConvertFrom-Json | 
Select-Object -ExpandProperty entry) | 
ForEach {
    $PSItem.'@name'
    $PSItem.'ip-netmask'
    $PSItem.'description'
    [System.Net.Dns]::GetHostEntry("$($PSItem.'ip-netmask')").HostName
}


# Results
...
37.193.217.222
37.193.217.222
test2
l37-193-217-222.novotelecom.ru
...

DNS名称是否配置了反向查找记录?如果您执行
ping-a
nslookup
操作,您会在那里找到名称吗?是的,其中一些操作仍然不起作用。使用原始json文件输入,我得到:调用带有“1”参数的“GetHostEntry”时出现异常:“主机名的大小太长,不能超过255个字符。参数名称:主机名”
(@'
{
"entry":[{
"@name":"31.170.162.203",
"ip-netmask":"31.170.162.203",
"description":"test1"}
,
{
"@name":"37.193.217.222",
"ip-netmask":"37.193.217.222",
"description":"test2"}
,
{
"@name":"46.17.63.169",
"ip-netmask":"46.17.63.169",
"description":"test3"}
]
}
'@ | 
ConvertFrom-Json | 
Select-Object -ExpandProperty entry).'ip-netmask' | 
ForEach {
    $PSItem
    [System.Net.Dns]::GetHostEntry("$PSItem").HostName
}

#Results
...
37.193.217.222
l37-193-217-222.novotelecom.ru
...
(@'
{
"entry":[{
"@name":"31.170.162.203",
"ip-netmask":"31.170.162.203",
"description":"test1"}
,
{
"@name":"37.193.217.222",
"ip-netmask":"37.193.217.222",
"description":"test2"}
,
{
"@name":"46.17.63.169",
"ip-netmask":"46.17.63.169",
"description":"test3"}
]
}
'@ | 
ConvertFrom-Json | 
Select-Object -ExpandProperty entry) | 
ForEach {
    $PSItem.'@name'
    $PSItem.'ip-netmask'
    $PSItem.'description'
    [System.Net.Dns]::GetHostEntry("$($PSItem.'ip-netmask')").HostName
}


# Results
...
37.193.217.222
37.193.217.222
test2
l37-193-217-222.novotelecom.ru
...