Zeaun.com
  • Support
Zeaun.com
  • Support
Information Technology Mastery,

Tutorial: Public IP Address Identification with PowerShell

by zupreme8 months agono comment
0
Shares
Share on FacebookShare on Twitter
image-12

A common task-within-a-task for Sysadmins is locating the Public-facing IP Address for a given Windows Server.

This may be done for the purposes of testing a new web app, or for the configuration of public DNS records.

Whatever the reason, here is an easy way to obtain that information without using a browser (especially since many sites which claim to be for public IP address identification are packed with ads, scripts, and other elements a wise System Administrator would avoid accessing from a server, especially while logged in with administrative credentials.

First, we assign a target URL to a variable called “$zurl”. The URL provided returns the data we need when called.

Assigning the $zurl variable

Now we have our URL stored as a string variable. You can always test the contents of a string variable by simply typing the variable name and pressing ENTER.

Displaying the contents of the $zurl variable

Now that we have the URL as a variable, we need a way to download data. This time we will use the NET.Webclient library from Microsoft. It’s already built into Windows, so let’s assign it to a variable as follows.

Assigning NET.Webclient to a variable, with which we will download data

We now have both our target URL and our web client as variables within system memory, ready for use. Let’s proceed to getting the Public IP value.

Read these errors carefully. They relate to an earlier lesson here.

Oh look. We got an SSL error. If you have been following this series carefully, you already know how to address this but, of course, we will cover it again here.

The part enclosed in green is what “fixes” the SSL error
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12"

That should take care of the TLS 1.2 incompatibility which is the PowerShell (and Internet Explorer) default on most Windows Servers today. Let’s rerun the prior line to see the difference.

With TLS 1.2 enabled for PowerShell, this worked like a charm

Alright, we have our Public IP address data stored now, in a variable called $zpublic, which could then be used for other operations or apps, should you desire. An example may be to programmatically update a DNS record, or to programmatically update this value in a database.

Pay no attention to the green bar….

Clearly I was not going to show you the public IP of my system (what kind of IT Security Professional would I be if I did…), but what is shown is sufficient for you to retrieve your own Public IP address values, using a public-facing service that Amerihub provides (at this time) for free.

Now please, go forth and use this newfound knowledge (which is Power, they say) for Good instead of for Evil.

And if you found this valuable, or if you find any of these tutorials valuable for your career or your business, donate here:

https://cash.app/$Zeaun

Previous

Browsing NASA’s Image of The Day Archive using PowerShell

8 months ago
Next

Tutorial: Getting the current price of Bitcoin using Powershell (USD, EUR, & GBP)

8 months ago

Leave a Reply Cancel reply

Related posts

pop1
Information Technology Mastery,

PowerShell Tutorial: Programmatically Retrieving the Population of each US State

by zupreme8 months agono comment
coin10
Information Technology Mastery,

Tutorial: Getting the current price of Bitcoin using Powershell (USD, EUR, & GBP)

by zupreme8 months agono comment
image-3
Information Technology Mastery,

Browsing NASA’s Image of The Day Archive using PowerShell

by zupreme8 months agono comment
ps9
Information Technology Mastery,

Getting Latitude and Longitude for a given Zip Code with PowerShell

by zupreme8 months agono comment

© 2020 Zeaun Zarrieff. All rights reserved.