Click here to Skip to main content
13,662,031 members
Click here to Skip to main content
Add your own
alternative version


25 bookmarked
Posted 6 Oct 2007
Licenced Ms-PL

VBScript for Sending IP Information to an E-mail Address

, 6 Oct 2007
Rate this:
Please Sign up or sign in to vote.
VBScript for sending IP information to an e-mail address


At home, I have a PPPoE connection and the IP address is changing almost every time. I am usually in the need to connect to my home computer from external locations, but I cannot setup a fixed remote desktop connection since I don't have a fixed IP. Also, I need the connection to be dialled automatically when the computer starts, without the need of phone guidance to the other person.

This article contains two simple scripts that:

  1. Dial the connection, and 
  2. Send the IP information to an e-mail account for use

Using the Code

The VB script uses CDO for e-mail transport and WMI for IP retrieval. Since the script is commented and explanations of CDO and WMI methods are easy to find, here it is:

' send the IP address via Gmail 
Sub SendIPInfo()

  On Error Resume Next

  Dim iMsg, iConf, Flds

  Set iMsg = CreateObject("CDO.Message")
  Set iConf = CreateObject("CDO.Configuration")
  Set Flds = iConf.Fields

  schema = ""

  Flds.Item(schema & "sendusing") = 2
  Flds.Item(schema & "smtpserver") = "" 
  Flds.Item(schema & "smtpserverport") = 465
  Flds.Item(schema & "smtpauthenticate") = 1
  Flds.Item(schema & "sendusername") = ""
  Flds.Item(schema & "sendpassword") = "your-gmail-password"
  Flds.Item(schema & "smtpusessl") = 1

  ' message body
  strDate = CStr(Date()) & " " & CStr(Time())
  strBody = "---===---<br/>IP info YOURCOMPUTER " & strDate & " <br/><br/>"

  ' read adapters info
  strComputer = "."
  Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  Set colNicConfigs = objWMIService.ExecQuery _
   ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
  For Each objNicConfig In colNicConfigs
    strDescription = objNicConfig.Description
    IPAddress = objNicConfig.IPAddress
    strIP = ""
    For Each s in IPAddress
      if strIP = "" then
        strIP = s
        strIP = strIP & ";" & s
      end if
    strBody = strBody & "<br/>" & _ 
      "Description:" & strDescription & "<br/>" & _ 
      "IP: " & strIP & "<br/>"
  strBody = strBody & "---===---" 

  With iMsg
    .To = "Sender Name <>"
    .From = "Receiver Name <>"
    .Subject = "IP info YOURCOMPUTER on: " & strDate
    .HTMLBody = strBody 
    .Sender = "Sender Name"
    .Organization = "Your Organisation"
    .ReplyTo = ""
    Set .Configuration = iConf

  End With 
  ' release interfaces
  Set iMsg = nothing
  Set iConf = nothing
  Set Flds = nothing
End Sub  


Just replace YOURCOMPUTER with your computer name, and your-gmail-username and your-gmail-password with the appropriate GMail identification.
Save the content of the script (or the attached on a location of choice (I am using C:\etc) and also secure the folder to grant access only to you (since the file contains the e-mail user name and password).

* * *

The other thing is how to automatically dialup the PPPoE connection at startup.

For this, it is enough to create a batch file, such as:

@echo off
if %1 EQU connect goto l_connect
if %1 EQU disconnect goto l_disconnect
goto l_unknown

rasdial CONN_NAME connUser connPassword
goto l_end

rasdial CONN_NAME /disconnect
goto l_end

@echo Unknown option %1
goto l_end


Replace the CONN_NAME with the name of connection as is listed in Network Connections, as well as connUser and connPassword with the identification from ISP. Again, save the file in a secure location (I'm using C:\etc\inet.bat) so it cannot be read or written except your account.

One more step is needed in order to make it automatically executed: execute gpedit.msc, go to Computer Configuration/Windows Settings/Scripts and double click the Startup. In Startup properties, click Add... and set the Script Name to C:\etc\inet.bat and Script Parameters to connect. (If you also need to disconnect on shutdown for some reason, double click Shutdown and set disconnect instead of connect on Script Parameters).

After adding the autodial script inet.bat, just repeat the same steps for adding the upper script, ipsend.vbs (after editing it). AFAIK, the startup scripts are executed sequentially so first will be the connection dialled and then the email will be sent. (For convenience, both .bat and the .vbs file can be called from a single windows-startup.bat file that does the dial and then the email job).


  • 6th October, 2007: Initial post


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Cristian Amarie
Team Leader BitDefender
Romania Romania
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralDynamic DNS Pin
scarecrow90010-Oct-07 21:18
memberscarecrow90010-Oct-07 21:18 
GeneralRe: Dynamic DNS Pin
Cristian Amarie10-Oct-07 21:30
memberCristian Amarie10-Oct-07 21:30 
GeneralRe: Dynamic DNS Pin
Irwan Hassan14-Oct-07 6:11
memberIrwan Hassan14-Oct-07 6:11 
GeneralRe: Dynamic DNS Pin
Cristian Amarie14-Oct-07 6:17
memberCristian Amarie14-Oct-07 6:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180810.1 | Last Updated 7 Oct 2007
Article Copyright 2007 by Cristian Amarie
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid