Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 36188

Publish Your Home Internet Connection IP Address Using Azure Blobs- Part 1

$
0
0

Scenario

Ever wanted to be able to access your home server while your on the go, but you don't know its IP Address ? Or maybe it changed ?

Background

I have a server at home which I use to host number of virtual machines that I use for performing some labs or tests. I have a VM on that server that is published on the internet through my home internet connection. Since I travel a lot, I find it sometimes challenging to connect to this VM and hence to my home server to work remotely.

On any usual day, I usually open Bing and just type What is my IP and Bing just write it back to me or gives me number of websites that can tell what is my public IP address, I record that IP somewhere and connect to it whenever I want to play with my home server. But from time to time, the IP address changes for various reasons, and I need to check again what is the new IP address or ask somebody at home to try to figure it out (and I spend considerable amount of time attempting to explain how to do that, and that is IP and what are those numbers 😃), so for the soul purpose of saving myself all this hassle, I went looking for any free solution that can help me figure out my home connection IP address while I'm not connected to my home network.

In my quest, I managed to come with an idea that is not so bad which allows me to easily find my home IP address, the only requirement for this solution is having an Azure Subscription, and the Azure Powershell module

In this 2 parts blog, I will be discussing the details of this solution

The Solution

The basic idea of the solution is to utilize the Azure Blob Storage to write a file that contains my home connection IP address from a VM or a PC running at home, and since the file is writing to a Blob in my Azure subscription, I can access it from anywhere on the planet

There are mainly to parts to this solution:

  1. Finding my home connection IP address
  2. Writing the IP address to a file and uploading it to an Azure Blob

In this blog post, I will be discussing the first part, while in the next blog article, I will be discussing the second part.

Part 1 - Finding my IP Address

So how can I figure my IP address in an automated way? remember, I'm not at home, so something needs to find it for me, and sure it's not my wife or kids.

Powershell to the rescue

While I was searching for how to figure out my IP address using Powershell, I found a clever script written by Aman Dhally (http://www.amandhally.net/2012/10/04/powershell-script-to-get-static-ip-address-or-public-ip-address-of-internet-connection/).

The Idea is simple, using Powershell, I would create a simple request to any of the public websites that can figure out my IP address, In this case http://checkip.dyndns.com and parse the response.

Browsing manually to the following URL http://checkip.dyndns.org in your favorite browser gets you the following page

As you can see, it's a simple page with your IP address written to it. All I need to do is to grab this IP and write it to a file, simple 😃

Now I made some modifications to Aman's original script, and the one I'm using is as follow:

function GetMyIP(){
    $DDNSIPCheckerUrl = "http://checkip.dyndns.com"
    $WebClient = New-Object System.Net.Webclient
    $DDNSResponse = $WebClient.DownloadString($DDNSIPCheckerUrl)
    
    $Regex = [regex] "d{1,3}.d{1,3}.d{1,3}.d{1,3}"
    $RegExResult = $Regex.Match($DDNSResponse)

    If($RegExResult.Success){
        $IPAddress = $DDNSResponse.Substring($RegExResult.Index,$RegExResult.Length)
        return $IPAddress     
    }
    else{
        return 0
    }
}

To test this function, copy and paste the code above into Powershell, then type GetMyIP and hit enter.

So what I'm (more accurately, Aman) doing is that I'm creating a WebClient object to send an HTTP get request (as if I'm the browser) and storing the reply in a Powershell variable $DDNSResponse, then I'm using Regular Expressions to search the web server response for a string that looks like an IP address (xxx.xxx.xxx.xxx), extract that IP then return it, and just in case the response does not contain any IP address, return 0.

Give it a try at home, or work, or any place 😃
See you in the part 2

Disclaimer – All scripts and reports are provided ‘AS IS’

This sample script is not supported under any Microsoft standard support program or service. This sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of this sample script and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of this script be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use this sample script or documentation, even if Microsoft has been advised of the possibility of such damages.


Viewing all articles
Browse latest Browse all 36188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>