-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyIP.vbs
More file actions
66 lines (58 loc) · 2.06 KB
/
Copy pathMyIP.vbs
File metadata and controls
66 lines (58 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
Option Explicit
Const ForReading = 1
Const ForWriting = 2
Dim sCurrentIPFile, oFSO, url, oHTTP
Dim oFile, sCurrentIP, sPreviousIP
Dim oEmail, sEmailFrom, sEmailTo, sEmailSubject, sSMTPServer
sEmailFrom = "nobodaddy@nowhere.net"
sEmailTo = "stugart@gmail.com"
sEmailSubject = "IP ADDRESS CHANGE"
sSMTPServer = "192.168.0.1"
Set oFSO = CreateObject("Scripting.FileSystemObject")
sCurrentIPFile = "C:\Documents and Settings\Shawn\Desktop\CurrentIP.txt"
url="http://checkip.dyndns.org"
On Error Resume Next
Set oHTTP = CreateObject("MSXML2.XMLHTTP")
Call oHTTP.Open("GET", url, FALSE)
oHTTP.Send
sCurrentIP = (oHTTP.ResponseText)
If Err.Number <> 0 Then
sCurrentIP = "AN ERROR OCCURRED RETRIEVING YOUR PUBLIC " _
& "IP ADDRESS FROM " & url & " AT " & Now
End If
sCurrentIP = Replace(sCurrentIP, "<html><head><title>Current IP Check" _
& "</title></head><body>", "")
sCurrentIP = Replace(sCurrentIP, "</body></html>", "")
sCurrentIP = Left(sCurrentIP, Len(sCurrentIP) - 1) 'for some reason, the url response text
If Not oFSO.FileExists(sCurrentIPFile) Then 'has an extra carriage return we'll remove here.
Set oFile = oFSO.CreateTextFile(sCurrentIPFile)
oFile.Write(sCurrentIP)
oFile.Close
MailMe sCurrentIP
WScript.Quit
End If
Set oFile = oFSO.OpenTextFile(sCurrentIPFile, ForReading)
sPreviousIP = oFile.ReadLine
If strComp(sPreviousIP, sCurrentIP, vbTextCompare) = 0 Then
MailMe sCurrentIP
WScript.Quit
Else
Set oFile = oFSO.OpenTextFile(sCurrentIPFile, ForWriting)
oFile.WriteLine(sCurrentIP)
MailMe sCurrentIP
End If
Sub MailMe(sNewIP)
Set oEmail = CreateObject("CDO.Message")
oEmail.From = sEmailFrom
oEmail.To = sEmailTo
oEmail.Subject = sEmailSubject
oEmail.Textbody = sNewIP
oEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sSMTPServer
oEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oEmail.Configuration.Fields.Update
oEmail.Send
End Sub