Automatically send my website a txt file when my home's public ip address changes

Hi,

After searching for about a half hour, I figure that it is time to ask the question.  I had a VB script that updated a file (ExternalIP.txt) on my website when BrightHouse changed my public IP address.  This VB script ran on my old 386 Dell PC running XP.  After being on line (24/7/365) since 1998, it finally died.  So, I moved the scripts to a DELL, Core 2 Duo, 32bit running Windows 7 Professional.  I have the new DELL, running 24/7/365 and set for always on.  The PC boots up and opens windows, a user automatically logs on with "Administrator" rights.  Not a single of the DOS batch files run (scheduled daily), and none of the VB scripts run (scheduled daily).  I have tried numerous ways of requesting the programs/bats to run with no luck.  Here are a few of the VBscripts and DOS bats used in the Windows 7 scheduler.

Thanks in advance for any assistance,

Don

In Windows Scheduler:
(worked in XP without the //Nologo)

c:\\Windows\System32\CScript.exe //Nologo c:\GetIP.vbs

CScript.exe //Nologo c:\Program Files\WeatherCapture\Weather.EXE

CScript.exe c:\Program Files\WeatherCapture\Weather.EXE

----------------------------------------
FTP batch file: (worked with XP)
cd\
ftp -s:DosFtpFile.ftp ftp.mywebsite.com
quit

DosFtpFile.ftp
ID
PW
delete ExternalIP.txt
ascii
put ExternalIP.txt
close
quit
-----------------------------------------
Sample ExternalIP.txt file contents
62.684.229.33	, 1/27/2015


This VBscript worked in XP but not Win7.. I have tried so many changes to it that I doubt it would run now
-----------------------------------------------
Const ForReading = 1
Const ForAppending = 8
Dim ipLog, objHTTP, strHTML, varStart
Dim varStop, strIP, strCurrIP, objFSO
Dim txtFile, strLine, objShell

' Log for tracking external IP addresses
ipLog = "ExternalIP.txt"

' Get current external IP address from web
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
Call objHTTP.Open("GET", "http://checkip.dyndns.org", False)
objHTTP.Send()
strHTML = objHTTP.ResponseText

' Extarct IP from HTML if HTML was recieved
If strHTML <> "" Then
	varStart = InStr(1, strHTML, "Current IP Address:", vbTextCompare) + 19
	If varStart Then varStop = InStr(varStart, strHTML, "</body>", vbTextCompare)
	If varStart And varStop Then strIP = Mid(strHTML, varStart, varStop - varStart)
Else
	strIP = "Unavailable"
End If
' Remove preceeding or trailing spaces
strCurrIP = Trim(strIP)

' Check for log file and last log entry
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not (objFSO.FileExists(ipLog)) Then 
	' If log file doesn't exist create it
	Set txtFile = objFSO.CreateTextFile(ipLog, True)
	strIP = ""
Else
	' Get last external IP address entry from log file
	Set txtFile = objFSO.OpenTextFile(ipLog, ForReading)
	Do Until txtFile.AtEndOfStream
	   strLine = txtFile.ReadLine
	   If Len(strLine) > 0 Then
		  strIP = strLine
	   End If
	Loop
	
End If
txtFile.Close

' Extarct last external IP from log file entry
If strIP <> "" Then
	varStart = 1
	varStop = InStr(varStart, strIP, ",", vbTextCompare) - 1
	If varStop Then strIP = Mid(strIP, varStart, varStop - varStart)
	' Remove preceeding or trailing spaces
	Trim(strIP)
Else
	strIP = "Unavailable"
End If

' Copy IP to clipboard
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "CMD /C ECHO " & strCurrIP & " | CLIP", 2

' Check if external IP has changed
If strCurrIP = strIP Then
	' If unchanged display IP
	'MsgBox "External IP:  " & strCurrIP & " is unchanged"
	x = 2
Else
	' If changed log to file and display IP
	Set txtFile = objFSO.OpenTextFile(ipLog, ForAppending)
	txtFile.Write(strCurrIP & vbTab & ", " & Date & vbCrLf)
	txtFile.Close
	'cscript DosFtpFile.bat
	'CScript.exe //Nologo c:\DosFtpFile.bat
	'MsgBox "External IP:  " & strCurrIP & vbCrLf & "This IP address has been logged"
End If


' Clear variables
Set ipLog = Nothing
Set objHTTP = Nothing
Set strHTML = Nothing
Set varStart = Nothing
Set varStop = Nothing
Set strIP = Nothing
Set strCurrIP = Nothing
Set objFSO = Nothing
Set txtFile = Nothing
Set strLine = Nothing
Set objShell = Nothing

May 25th, 2015 1:52pm

Boy did you invent a a Rub Goldberg. 

Just do this:

$MyPublicIP= (Invoke-WebRequest ifconfig.me/ip).Content

Save to registry or file and schedule to run.

 

Free Windows Admin Tool Kit Click here and download it now
May 25th, 2015 2:07pm

Or this if you don't have PowerShell 3.0 or later:

$ip = (New-Object System.Net.WebClient).DownloadString('https://api.ipify.org')

May 25th, 2015 2:11pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics