Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
RichEdit1: TRichEdit;
Button1: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;
Var
Form1 : TForm1;
PostDataStream : TStringStream;
Procedure TForm1.Button1Click(Sender : TObject);
Var
IPAddr : String;
I : Integer;
Begin
IdHTTP1.Request.Username := 'userid';
IdHTTP1.Request.Password := 'password';
IdHTTP1.Request.ProxyUsername := 'userid';
IdHTTP1.Request.ProxyPassword := 'password';
try
PostDataStream := TStringStream.Create('');
// Put the IE http address here that shows when your router is displaying the
// internet IP. Mine is a NetGear WGT624 V2 ... so this is it's addr Note: The NetGear is case sensitive...
IDHTTP1.Get('[URL unfurl="true"]http://192.168.100.1/RST_st_dhcp.htm',[/URL] PostDataStream);
// If not caught by exception, we're o.k.
RichEdit1.Clear;
RichEdit1.Text := PostDataStream.DataString;
PostDataStream.Free;
except
on E: exception do // On Exception, just flag it
Begin
PostDataStream.Free;
End;
end;
If (RichEdit1.Lines.Count > 0) Then
Begin
I := 0;
While (I < RichEdit1.Lines.Count) Do
Begin
// Parse lines for line that contains IP
If (Pos('xxxxx', RichEdit1.Lines.Strings[I]) > 0) // if beginning str there
and
(Pos('yyyyy', RichEdit1.Lines.Strings[I] > 0) Then // if trailing str there
Begin
IPAddr := Copy(RichEdit1.Lines.Strings[I], x, y);
Break;
End
Else
Inc(I);
End;
If (I < RichEdit1.Lines.Count) Then
Begin
// Do something with IPAddr
End
Else
Begin
// Not Found in html
End;
End;
End;
:
:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls, strutils;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
IdHTTP1: TIdHTTP;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var dtstream : tstringstream;
s : string;
p : integer;
begin
dtstream := tstringstream.create('');
idhttp1.Get('[URL unfurl="true"]http://www.whatismyip.com',[/URL] dtstream);
s := dtstream.DataString;
p := pos('Your ip is',s);
s := copy(s,p+11,30);
p := pos(' ',s);
s := leftstr(s,p);
edit1.Text := s;
end;
end.
procedure TForm1.Button1Click(Sender: TObject);
function GetString(SearchStart, SearchStop, SearchString: String): String;
var
selStart, selStop: Integer;
s: String;
begin
Result := '';
selstart := PosEx(SearchStart, SearchString, 1) + Length(SearchStart);
selstop := PosEx(SearchStop, SearchString, selstart);
Result := Copy(SearchString, selstart, selstop-selstart);
end;
var
s: String;
begin
IdHTTP1.Request.Username := UsernameEdit.Text;
IdHTTP1.Request.Password := PasswordEdit.Text;
try
// Get root-page
s := IDHTTP1.Get('[URL unfurl="true"]http://'+IPEdit.Text+'/device_status.htm');[/URL]
s := GetString('document.location.href="', '"', s);
// Get sub-page
s := IDHTTP1.Get('[URL unfurl="true"]http://'+IPEdit.Text+'/'+s);[/URL]
s := GetString('WAN IP:', '<BR>', s);
ExternalIPEdit.Text := s;
except on e: Exception do
begin
ExternalIPEdit.Text := '0.0.0.0';
MessageDlg(E.Message, mtError, [mbOK], 0);
end;
end;
end;
/Cheers...
uses
ShellApi
..
shellexecute(Handle,'open','c:\xx\myipconf.bat','','',sw_Hide);