Jump to content

Recommended Posts

Posted

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.

Posted
$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"
}

Posted

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.

Posted
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")

  • 1 month later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...