Hello all,
If your provider give you an IP that is changed in every period,
here is a program that i have wrote that updates your HTML web pages with the new IP and updates also the IP of your webserver programaticaly and restart your webserver and also upload the necessary files with an FTP client to your ftp server of your internet provider.
Here is the VB script that i have wrote that will be called by the Object Pascal program:
===
dim objWebApp
dim intArraySize
dim arrOldBindings
dim arrNewBindings
Set oArgs = WScript.Arguments
Set objWebApp = GetObject("IIS://localhost/w3svc/1")
If isArray(objWebApp.ServerBindings) then
arrOldBindings = objWebApp.ServerBindings
intArraySize = UBound(arrOldBindings)
Redim arrNewBindings(intArraySize + 1)
For i = 0 to intArraySize
arrNewBindings(i) = arrOldBindings(i)
Next
WScript.Echo oArgs(0)
str=oArgs(0)
arrNewBindings(intArraySize) = str
'"12.12.12.12:88:"
objWebApp.Put "ServerBindings", (arrNewBindings)
objWebApp.SetInfo
End If
==
And here is the Object Pascal program that i have wrote for you
===
program test;
uses windows,classes,sysutils,Winsock,ALWinInetFTPClient;
var list:TStrings;
i:integer;
fstream:TFilestream;
StrIP:string;
handle:thandle;
ftp:TALWinInetFTPClient;
{...}
function ShellExecute(hWnd: HWND; Operation, FileName, Parameters,
Directory: PChar; ShowCmd: Integer): HINST; stdcall;external 'shell32.dll' name 'ShellExecuteA';
function Stream2String(Stream1: TStream;var Mystring:string): boolean;
begin
result:=true;
try
try
Stream1.Position := 0;
SetLength(Mystring, Stream1.Size);
Stream1.ReadBuffer(Pointer(Mystring)^, Stream1.Size);
finally
// Stream1.Free;
end;
except
result:=false;
end;
end;
function getIPs: Tstrings;
type
TaPInAddr = array[0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe: PHostEnt;
pptr: PaPInAddr;
Buffer: array[0..63] of Char;
I: Integer;
GInitData: TWSAData;
begin
WSAStartup($101, GInitData);
Result := TstringList.Create;
Result.Clear;
GetHostName(Buffer, SizeOf(Buffer));
phe := GetHostByName(buffer);
if phe = nil then Exit;
pPtr := PaPInAddr(phe^.h_addr_list);
I := 0;
while pPtr^
<> nil do
begin
Result.Add(inet_ntoa(pptr^^));
Inc(I);
end;
WSACleanup;
end;
procedure FileReplaceString(const FileName, searchstring, replacestring: string);
var
fs: TFileStream;
S: string;
begin
fs := TFileStream.Create(FileName, fmOpenread or fmShareDenyNone);
try
SetLength(S, fs.Size);
fs.ReadBuffer(S[1], fs.Size);
finally
fs.Free;
end;
S := StringReplace(S, SearchString, replaceString, [rfReplaceAll, rfIgnoreCase]);
fs := TFileStream.Create(FileName, fmCreate);
try
fs.WriteBuffer(S[1], Length(S));
finally
fs.Free;
end;
end;
begin
repeat
fstream:=TFileStream.create('ip.txt',fmOpenReadWrite);
Stream2String(fstream,StrIP);
list := GetIps;
If StrIP <> list[0]
then
begin
FileReplaceString('Tree.html',StrIP,list[0]);
FileReplaceString('Home.html',StrIP,list[0]);
fstream.size:=0;
fstream.WriteBuffer(list[0][1], Length(list[0]));
ShellExecute(Handle,'open', pchar('cscript.exe'),pchar('iis.vbs '+list[0]+':88:'),nil,SW_HIDE{SW_SHOWNORMAL});
ShellExecute(Handle,'open', pchar('net.exe'),pchar(' stop w3svc'),nil,SW_HIDE{SW_SHOWNORMAL});
ShellExecute(Handle,'open', pchar('net.exe'),pchar(' start w3svc'),nil,SW_HIDE{SW_SHOWNORMAL});
ftp:=TALWinInetFTPClient.create(nil);
ftp.UserName:='****l';
ftp.Password:='****';
ftp.serverport:=21;
ftp.ServerName:='pages.videotron.com';
ftp.transfertype:=wFtpTt_BINARY;
ftp.connect;
ftp.PutFile('home.html','home.html');
//ftp.PutFile('tree.html','tree.html');
ftp.disconnect;
ftp.free;
end;
list.free;
fstream.free;
sleep(1000*60*5);
until false;
end.
===
and you can download TALWinInetFTPClient v.3.79 that i am usgin from:
http://www.torry.net/quicksearchd.php?String=ftp+client&Title=Yes
And don't forget to configure tour firewall to alloe active FTP clients,
here is how you can do it for Windows 2008 server:
http://morndej.wordpress.com/2012/05/17/how-to-add-windows-2008-firewall-rule-to-allow-active-ftp-client/
Thank you,
Amine Moulay Ramdane.