{===============================================================================}
{ Script name: GetMyIP.iss }
{ Script version: 1.1 }
{ Author: Serega, [url]http://forum.oszone.net/member.php?userid=88670[/url] }
{ Finishings: Habetdin, nik1967 }
{ }
{ This script shows how to learn your IP }
{ Этот скрипт показывает, как узнать свой IP }
{===============================================================================}
var
lbl: TLabel;
Button: TButton;
function GetHtmlSource(const url: string): string;
var
vHttp: Variant;
begin
try
vHttp := CreateOleObject('Microsoft.XMLHTTP');
vHttp.open('GET', url, False);
vHttp.send;
Result := vHttp.responseText;
lbl.Font.Color:= clGreen;
except
Result := 'интернет отключен';
lbl.Font.Color:= clRed;
end;
end;
procedure ButtonClick(Sender: TObject);
var
strHtml: string;
begin
strHtml := GetHtmlSource('http://automation.whatismyip.com/n09230945.asp');
lbl.Caption := 'Ваш IP адрес: ' + Trim(strHtml);
end;
procedure InitializeWizard();
var
strHtml: string;
begin
with WizardForm do begin
ClientWidth := ScaleX(260);
ClientHeight:= ScaleX(80);
BorderStyle := bsDialog;
OuterNotebook.Hide;
Center;
Caption := 'Ваш IP адрес';
end;
WizardForm.CancelButton.SetBounds(ScaleX(150), ScaleY(47), ScaleX(85), ScaleY(23));
WizardForm.CancelButton.Parent := WizardForm;
Button := TButton.Create(WizardForm);
with Button do begin
Parent := WizardForm;
SetBounds(ScaleX(25), ScaleY(47), ScaleX(85), ScaleY(23));
Caption := 'Узнать IP';
OnClick := @ButtonClick;
end;
lbl := TLabel.Create(WizardForm);
with lbl do begin
Alignment:= taCenter;
WordWrap:= true;
Parent := WizardForm;
AutoSize := False;
Left := ScaleX(-5);
Top := ScaleY(17);
Width := ScaleX(270);
Height:= ScaleX(80);
Font.Size := 12;
end;
strHtml := GetHtmlSource('http://automation.whatismyip.com/n09230945.asp');
lbl.Caption := 'Ваш IP адрес: ' + Trim(strHtml);
end;
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
Confirm := False;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
WizardForm.CancelButton.Caption := 'Закрыть';
end;[/SOURCE][/MORE]
И ещё
[MORE="Внутренний + внешний IP"][SOURCE="inno"][Setup]
AppName=MyIP
AppVerName=MyIP v 1.2
DefaultDirName={pf}\MyIP
DefaultGroupName=MyIP
OutputDir=.
Compression=lzma2/ultra
InternalCompressLevel=ultra
SolidCompression=yes
OutputBaseFilename=MyIP_int_ext
[Code]
type
IP_ADDR_INFO = array of record
Description: String;
IPv4: String;
IPv6: String;
end;
function MessageBox(hWnd: HWND; lpText, lpCaption: PAnsiChar; uType: LongWord): Integer; external 'MessageBoxA@user32.dll stdcall';
function GetHtmlSource(const url: string): string;
var
vHttp: Variant;
begin
try
vHttp := CreateOleObject('Microsoft.XMLHTTP');
vHttp.open('GET', url, False);
vHttp.send;
Result := vHttp.responseText;
except
Result := 'is not available';
end;
end;
function GetLocalIP(var IPAddrInfo: IP_ADDR_INFO): Boolean;
var
objSWbemLocator, objSWbemServices, objSWbemObjectSet, objRegExp, objRegExpMatches: Variant;
IndexCount, i: Byte;
strBuf, ptrnIPv4, ptrnIPv6: String;
begin
try
objSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
objRegExp := CreateOleObject('VBScript.RegExp');
except
ShowExceptionMessage;
Exit;
end;
ptrnIPv4 := '(\d{1,3}[.]){3}\d{1,3}'; //IPv4 regexp
ptrnIPv6 := //IPv6 regexp
'(([0-9a-fA-F]{1,4}:){1,1}(:[0-9a-fA-F]{1,4}){1,6})|(([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5})|' +
'(([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4})|//(([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3})|' +
'(([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2})|(([0-9a-fA-F]{1,4}:){1,6}(:[0-9a-fA-F]{1,4}){1,1})|' +
'((([0-9a-fA-F]{1,4}:){1,7}|:):)|(:(:[0-9a-fA-F]{1,4}){1,7})|(((([0-9a-fA-F]{1,4}:){6})(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}))|' +
'((([0-9a-fA-F]{1,4}:){5}[0-9a-fA-F]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}))|' +
'(([0-9a-fA-F]{1,4}:){5}:[0-9a-fA-F]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})|' +
'(([0-9a-fA-F]{1,4}:){1,1}(:[0-9a-fA-F]{1,4}){1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})|' +
'(([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,3}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})|' +
'(([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,2}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})';
objSWbemServices := objSWbemLocator.ConnectServer();
objSWbemServices.Security_.ImpersonationLevel := 3;
IndexCount := objSWbemServices.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration').Count;
objSWbemObjectSet := objSWbemServices.ExecQuery('SELECT Description,IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE');
for i := 0 to IndexCount-1 do
try
SetArrayLength(IPAddrInfo, GetArrayLength(IPAddrInfo)+1);
strBuf := objSWbemObjectSet.Item('Win32_NetworkAdapterConfiguration.Index=' + IntToStr(i)).GetObjectText_;
IPAddrInfo[GetArrayLength(IPAddrInfo)-1].Description := objSWbemObjectSet.Item('Win32_NetworkAdapterConfiguration.Index=' + IntToStr(i)).Properties_.Item('Description').Value;
objRegExp.Pattern := ptrnIPv4;
if objRegExp.Test(strBuf) then
begin
objRegExpMatches := objRegExp.Execute(strBuf);
IPAddrInfo[GetArrayLength(IPAddrInfo)-1].IPv4 := objRegExpMatches.Item[0].Value;
end;
objRegExp.Pattern := ptrnIPv6;
if objRegExp.Test(strBuf) then
begin
objRegExpMatches := objRegExp.Execute(strBuf);
IPAddrInfo[GetArrayLength(IPAddrInfo)-1].IPv6 := objRegExpMatches.Item[0].Value;
end;
except
GetExceptionMessage;
SetArrayLength(IPAddrInfo, GetArrayLength(IPAddrInfo)-1);
end;
Result := (GetArrayLength(IPAddrInfo) > 0);
end;
function InitializeSetup: Boolean;
var
i: Byte;
strHtml, url: string;
arr: IP_ADDR_INFO;
begin
strHtml := GetHtmlSource('http://automation.whatismyip.com/n09230945.asp');
if GetLocalIP(arr) then for i := 0 to GetArrayLength(arr)-1 do
MessageBox(0,
arr[i].Description + #13#10 +
'IPv4: ' + arr[i].IPv4 + #13#10 +
'IPv6: ' + arr[i].IPv6 + #13#10 +
'IP: ' + Trim(strHtml) + #13#10,
'MyIP', MB_ICONINFORMATION);
Result:=False;
end;[/SOURCE][/MORE]