Call me...


Hello
T he atheist rejects the claim that there is a
supernatural entity or force that interacts with existence...
Because it is a claim without basis.

Atheism makes no claims whatsoever.
Atheism asserts nothing.
Atheism IS NOT an act or an action
IT IS a position
 It has no objective.
Comparatively / Conversely:
Anti-theism IS an act or an action
 It IS NOT a position
 It has an objective.
Not all ATHEISTS are ANTI-THEIST.
All ANTI-THEISTS are ATHEIST.

Wednesday, March 3, 2010

Powershell - Sending IP address in email via GMAIL

I wanted to be able to Remote Desktop to my Home PC from work...

So, I had to enable RDP on the PC and set up port forwarding on my wireless router for  port 3389 (the machine I'm connecting to is Hard wired) - Port forwarding is easy enough, but the steps are specific to your brand of router (Google is your friend!). 

The last step was to open RDP on my work computer and connect to my home computer. To do this I needed the EXTERNAL IP address on my router. Your EXTERNAL IP information is not found on / in the physical machine you want to connect to if you use a router. It is presented to the outside facing portion of your network connection so you have to ask the outside world what IP address they see you using...

And the EXTERNAL IP is subject to change at various points in time depending on the dynamic IP lease / renew rate your ISP dictates... Unless you have a Static IP address. That is not to say that your dynamic IP address will change, but it can.

Rather than spending the money on a Static IP address, I decided to find a way to make my EXTERNAL IP address available to me while I was away (somehow). Enter Powershell...

(Note: I run Win 7 64 bit, so I use PS v2.0)

After some digging around / trial and error. I found a method that will ask for my EXTERNAL IP address (at 'http://checkip.dyndns.com:8245/') and send that information via e-mail (I use GMAIL) from my machine to my GMAIL account.

The initial return from grabbing the results of that websites information are brought in to Powershell as raw text (including the HTML tags):    
<html><head><title>Current IP Check</title></head><body>Current IP Address: xx.xx.xx.xx</body></html>




There are (of course) plenty of ways to remove the extraneous data and there are also ways to embed the HTML into the email...


I used this '-replace "[^\d\.]"' to strip out the tags and the letters (it replaces anything that is not a 'number' or a 'period', with a ~null~ value) - its function is also commented in the script:
    
This script is seeminly specific to GMAIL port and SSL requirements, but it may work for other systems as well.

I hope that this information can help someone else - in part or in whole:


##############  START ###############
$wc=New-Object net.webclient
$Results = $wc.downloadstring("http://checkip.dyndns.com:8245/") -replace "[^\d\.]"

#############################################################################################

####                       NOTES about " -replace "[^\d\.]"                              ####
####                                                                                     ####
#### "-Replace" replace "^" all Characters excluding "\d" numbers or "\." decimal points ####
####  ~ it literally only retains numbers and decimal points ~                           ####
####                                                                                     ####
#############################################################################################

$Username = "
XXXXXXXXXX" # account username goes inside the parenthesis
$PW = "xxxxxxxxxx" # account password goes inside the parenthesis"

$EmailFrom = "XXXXXXXX@gmail.com"
#FROM 'GMAIL' address goes inside the quote marks
$EmailTo = "xxxxxxxx@gmail.com"
# RECIPIENT address goes inside the quote marks
$Subject = "$Results - Home IP Address"

$Body = "$Results - Home IP Address"


$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($Username, $PW);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

##############  END ###############

14 comments:

  1. Wow i can say that this is another great article as expected of this blog.Bookmarked this site.. https://192-168-i-i.com/192-68-0-1/

    ReplyDelete
  2. This is truly a decent and enlightening, containing all data furthermore greatly affects the new innovation. A debt of gratitude is in order for sharing it my ip location

    ReplyDelete
  3. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..
    find social media links

    ReplyDelete
  4. Thanks For sharing this Superb article.I use this Article to show my assignment in college.it is useful For me Great Work. Aged 2008 to 2015 Old Gmail Accounts

    ReplyDelete
  5. I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. https://hotmail-iniciar-sesion.email/

    ReplyDelete
  6. Thank you so much for sharing this great blog.Very inspiring and helpful too.Hope you continue to share more of your ideas.I will definitely love to read. Buy PVA Gmail Accounts

    ReplyDelete
  7. We provide a range of packages of Google accounts for sale at a reasonable price. Our bundle begins from $30, which is the least fee for getting the full benefit of Google account. All the Google accounts are manually crafted accounts that are entirely worthy of investing your money. We offer the most reasonably priced applications in the market. Buy Gmail Accounts

    ReplyDelete
  8. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! https://hotmail-account.email

    ReplyDelete
  9. This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! entrar no hotmail

    ReplyDelete
  10. Here is a basic method to comprehend IP locations and how IP address approval can function for you. An Internet Protocol address (IP address) is a numerical mark appended to every gadget, as in a printer or PC that took part in a PC arrange utilizing Internet Protocol for correspondence. 192.168.1.1

    ReplyDelete
  11. email harvesting software is new technology and as such it carries a wide variety in its pricing. Just look around a bit and check out the different options and pricing to enable finding the one that will best fit the purposes of the business involved and end up with a better list than money can buy.

    ReplyDelete
  12. After this, the advertiser will send an email to the entirety of the email delivers requesting that individuals purchase his item. CBT Mass Email Sender Desktop Software

    ReplyDelete