MatthewL Posted December 16, 2020 Posted December 16, 2020 I am looking to create a powershell script (open to other methods if better), I will admit my scripting skills are rubbish. If I use Invoke-WebRequest command and point it to http://ip-api.com/json/ it gives various information. What I want to do is export the ISP and create a system variable with that so we can then run another script if ISP = xyz then deploy file to devices at home or if ISP = xyz create a text file c:\ispistrue.txt for example. I was initially looking to dump IP then look that up which is a bigger task so if I can get the ISP that would help. Any assistance would be welcome, thanks.
mavhc Posted December 16, 2020 Posted December 16, 2020 $Wcl = new-object System.Net.WebClient $Wcl.Headers.Add(“user-agent”, “PowerShell Script”) $Wcl.Proxy.Credentials = [system.Net.CredentialCache]::DefaultNetworkCredentials $a = invoke-webrequest "http://ip-api.com/json" | convertFrom-Json | select isp write-output $a.isp if ($a.isp -eq "Exa Networks Limited") { new-item -Path "C:\" -name "ispistrue.txt" -itemtype "File" } else { remove-item "c:\ispistrue.txt" }
chaplic Posted December 16, 2020 Posted December 16, 2020 (Invoke-RestMethod http://ip-api.com/json/).isp Should do what you want
MatthewL Posted December 16, 2020 Author Posted December 16, 2020 Mavhc that doesn't seem to work, even changing the name to say Virgin Media as mine is displayed. Chaplic that works, just need to output to a file but name is the same as output before any spaces i.e. my ISP is Virgin Media want it to save as virgin.txt or plusnet.txt if you get me.
RobD Posted December 16, 2020 Posted December 16, 2020 $ISP = (Invoke-RestMethod http://ip-api.com/json/).isp $ISP | out-file -filepath c:\temp\$ISP.txt
chaplic Posted December 16, 2020 Posted December 16, 2020 Mavhc that doesn't seem to work, even changing the name to say Virgin Media as mine is displayed. Chaplic that works, just need to output to a file but name is the same as output before any spaces i.e. my ISP is Virgin Media want it to save as virgin.txt or plusnet.txt if you get me. mahcv approach is probably better in terms of structure and figuring out what you did in 6 months time, but lets go with the single line "hello" | add-content -path $((((Invoke-RestMethod http://ip-api.com/json/).isp) -replace '\s','') + ".txt")
MatthewL Posted December 16, 2020 Author Posted December 16, 2020 Thanks for the quick replies, I can work with them I think, now do so some testing out there and see the results!
MatthewL Posted December 16, 2020 Author Posted December 16, 2020 So far so good, thanks for the quick replies to this earlier.
MatthewL Posted February 5, 2021 Author Posted February 5, 2021 Just going back to this, worked for that I need but now need to grab the external IP which works with: (Invoke-RestMethod http://ip-api.com/json/).isp Gives ISP (Invoke-RestMethod http://ip-api.com/json/).query Gives IP address Just cannot see to get the both i.e. isp.IPaddress Any thoughts.
psydii Posted February 5, 2021 Posted February 5, 2021 $details = (Invoke-RestMethod http://ip-api.com/json/) $details $details.isp $details.query $IPandISP = $details.isp + "." + $details.query $IPandISP 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now