Cannot get API call to whois.arin.net to work

I am a newbie trying to learn PS. I thought an easy learning opportunity would be to create a script to check ARIN’s API for a list of IPs (sourceip.txt) and output the results to a list apioutput.txt. While I worked through all the errors I had been receiving, I cannot get the output to work. Any assistance would be greatly appreciated.

$url_base = "http://whois.arin.net/rest/ip/"
$iplist = Get-Content -Path .\sourceIP.txt
$ips = $iplist -split "," -replace '["]'
foreach ($item in $ips){
Write-Output $item
#Write-Output $ips
$url = $url_base + $item
Write-Output $url
$header = @{"Accept" = "application/json"}
$response = Invoke-Webrequest -uri $url -Method "Get" -Headers $header
$response.Content.net | ConvertTo-Json
Write-Output $response.Content.net | Out-File -FilePath .\apioutput.txt
}```

jcrow,
Welcome to the forum. :wave:t4:

Unfortunately …

is not helpful at all. :wink: What does that mean? If you get error messages you should share them completely (formatted as code, please)

How does you input file look like? And what do you expect your output file to look like? (When you poast sample data format it as code as well, please).

I do not receive any errors or output, using Visual Studio Code. My input file looks like this (though I’ve substituted my IP list with random, private IP for the sake of an example:

10.10.10.0
192.168.4.24
10.240.10.0

I am not getting output to show you, but it would be a json version of this from Arin:

Network
Net Range	142.250.0.0 - 142.251.255.255
CIDR	142.250.0.0/15
Name	GOOGLE
Handle	NET-142-250-0-0-1
Parent	NET142 (NET-142-0-0-0-0)
Net Type	Direct Allocation
Origin AS	AS15169
Organization	Google LLC (GOGL)
Registration Date	2012-05-24
Last Updated	2012-05-24
Comments	
RESTful Link	https://whois.arin.net/rest/net/NET-142-250-0-0-1
See Also	Related POC records.
See Also	Related organization's POC records.
See Also	Related delegations.

Look at the output of

$response.content | ConvertFrom-Json | Select-Object -ExpandProperty net

You’ve got some work ahead of you to extract the desired info out of the object returned. There are several different nested properties.

@xmlns               : @{ns3=http://www.arin.net/whoisrws/netref/v2; ns2=http://www.arin.net/whoisrws/rdns/v1;
                       $=http://www.arin.net/whoisrws/core/v1}
@copyrightNotice     : Copyright 1997-2022, American Registry for Internet Numbers, Ltd.
@inaccuracyReportUrl : https://www.arin.net/resources/registry/whois/inaccuracy_reporting/
@termsOfUse          : https://www.arin.net/resources/registry/whois/tou/
registrationDate     : @{$=2016-02-01T15:18:40-05:00}
rdapRef              : @{$=https://rdap.arin.net/registry/ip/151.101.0.0}
ref                  : @{$=https://whois.arin.net/rest/net/NET-151-101-0-0-1}
endAddress           : @{$=151.101.255.255}
handle               : @{$=NET-151-101-0-0-1}
name                 : @{$=SKYCA-3}
netBlocks            : @{netBlock=}
resources            : @{@copyrightNotice=Copyright 1997-2022, American Registry for Internet Numbers, Ltd.;
                       @inaccuracyReportUrl=https://www.arin.net/resources/registry/whois/inaccuracy_reporting/;
                       @termsOfUse=https://www.arin.net/resources/registry/whois/tou/; limitExceeded=}
orgRef               : @{@handle=SKYCA-3; @name=Fastly; $=https://whois.arin.net/rest/org/SKYCA-3}
parentNetRef         : @{@handle=NET-151-0-0-0-0; @name=RIPE-ERX-151;
                       $=https://whois.arin.net/rest/net/NET-151-0-0-0-0}
startAddress         : @{$=151.101.0.0}
updateDate           : @{$=2021-12-14T20:28:34-05:00}
version              : @{$=4}
1 Like

Huuuiii … you’ve been faster than me. :+1:t4: :wink:

… and …
image

Happy birthday!! :clap:t4: :wink: :partying_face: :love_you_gesture:t4: :heart: :birthday: :champagne: :beers:

Thank you very much, Olaf!