KB

Send IP Address of a NIC to an Email Address

Schedule this script to periodically send IP address information to your alerts mailbox, for clients with a dynamic IP.

Note: this works by getting the output from "ipconfig /all" so is only useful if the client has their ADSL modem in bridging mode, and the external interface on the server gets the public IP address.

ReportIPAddresses.bat

@Echo Off
C:\Windows\System32\IPConfig.Exe /ALL > C:\Scripts\IPAddresses.Txt
C:\Windows\System32\CScript.Exe C:\Scripts\ReportIPAddresses.Vbs //B
If Exist C:\Scripts\IPAddresses.Txt Del C:\Scripts\IPAddresses.Txt

ReportIPAddresses.vbs

Option Explicit

Dim MailObj
Dim MailBody
Dim FS, FileObj

Set FS = CreateObject("Scripting.FileSystemObject")
Set FileObj = FS.OpenTextFile("C:\Scripts\IPAddresses.Txt", 1)

MailBody = "IPConfig /ALL Output at " & FormatDateTime(Now, 2) & " " & FormatDateTime(Now, 4) & vbCrLf

Do Until FileObj.AtEndOfStream
MailBody = MailBody & vbCrLf & FileObj.ReadLine
Loop

FileObj.Close
Set FileObj = Nothing
Set FS = Nothing

Set MailObj = CreateObject("CDONTS.NewMail")

MailObj.To = " This email address is being protected from spambots. You need JavaScript enabled to view it. "
MailObj.Importance = 2
MailObj.From = " This email address is being protected from spambots. You need JavaScript enabled to view it. "
MailObj.Subject = "Server IP Addresses at " & FormatDateTime(Now, 2) & " " & FormatDateTime(Now, 4)
MailObj.MailFormat = 0
MailObj.Body = MailBody

MailObj.Send

Set MailObj = Nothing

WScript.Echo "Mail Sent"