'-----------------------------------------------------------------------
'-----------------------------------------------------------------------
'Idealy you will set this to run in task scheduler once every so often.
'It will check the current ip address with an old ip address and if the
'ip has changed then it will email you the new ip address.
'Program was wrote on win98 machine. To use email you must have
'office installed on the computer you are gonna run this from.
'-----------------------------------------------------------------------
'This program creates 2 extra files in the scripts directory.
'Winipcfg.OUT & OldIP.txt
'-----------------------------------------------------------------------
'If you want to try this out without reconnecting then after you run the
'program change OldIP.txt to a different ip address.
'-----------------------------------------------------------------------
Dim CurrentIP, fso, IPFile, SPath, FileIP, OldIPFile, OldIP, EmailAddress
'-----------------------------------------------------------------------
'IMPORTANT ============================================================
'=======================================================================
'If there is more than one email address to send to then seperate them
'-----------------------------------------------------------------------
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
SPath = fso.GetAbsolutePathName("C:")
IPFile = SPath & "\winipcfg.out"
OldIPFile = SPath & "\oldip.txt"
'---------------------------------------------------------------------------
Main()
Sub Main()
If CheckForFile(IsThere) = 1 Then
GetOldIP()
RunBat()
CheckForNewIP()
If CurrentIP = OldIP Then
'Dont do anything because the ip address is the same :)
Else
WCurrentIP() 'write the current ip to log file
SendMail() 'send the updated ip to the email address
End If
Else
CreateBat()
CheckForNewIP()
WCurrentIP()
End If
set fso = nothing
set WshShell = nothing
End Sub
'---------------------------------------------------------------------------
Function CheckForFile(IsThere)
If fso.fileExists(IPFile) Then
CheckForFile = 1
Else
CreateBat()
Return = WshShell.Run("C:\GetIp.bat", 1, True)
CheckForFile = 0
End If
End Function
'---------------------------------------------------------------------------
Function CreateBat()
Dim BatFile
Set BatFile = fso.OpenTextFile("C:\GetIp.bat",2,True)
"winipcfg /batch" &vbcrlf &_
BatFile.Close
Set BatFile = Nothing
End Function
'---------------------------------------------------------------------------
Function GetOldIP()
Dim File, CLine
If fso.FileExists(OldIPFile) Then
Else
Set File = fso.OpenTextFile(OldIPFile,2,True)
File.write "No IP"
File.Close
End If
Set File = fso.OpenTextFile(OldIPFile,1)
CLine = File.ReadLine
OldIP = CLine
File.Close
Set File = Nothing
End Function
'---------------------------------------------------------------------------
Function CheckForNewIP()
Dim File, CLine
On Error Resume Next
Set File = fso.OpenTextFile(IPFile,1)
For i = 1 To 6 Step 1
CLine = File.ReadLine
Next
CurrentIP = Right(CLine,12)
File.Close
Set File = nothing
End Function
'---------------------------------------------------------------------------
Function WCurrentIP()
Dim File
Set File = fso.OpenTextFile(OldIPFile,2,True)
File.Write CurrentIP
File.Close
Set File = nothing
End Function
'---------------------------------------------------------------------------
Function RunBat()
Return = WshShell.Run("C:\GetIp.bat", 1, True)
End Function
Function SendMail()
set out=WScript.CreateObject("Outlook.Application")
set Message=out.CreateItem(0)
Message.Recipients.Add(EmailAddress)
Message.Subject = "IP CHANGE"
Message.Body = "IP Changed From " & OldIP & " to " & CurrentIP & "."
Message.Attachments.Add(IPFile)
Message.Send
Set out = Nothing
Set Message = Nothing
End Function
Quote:
> I want to write a script to that when run by a user on their machine
> will return the ip address allocated to the ppp dial up adaptor .
> Is this possible?
> Charlie Markwick