unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdIPWatch, winsock,
ExtCtrls;
type
TForm1 =
class
(TForm)
idpwtch1: TIdIPWatch;
edt2: TEdit;
lbl1: TLabel;
tmr1: TTimer;
lbl2: TLabel;
btn1: TButton;
btn2: TButton;
lbl3: TLabel;
lbl4: TLabel;
lbl5: TLabel;
lbl6: TLabel;
lbl7: TLabel;
lbl8: TLabel;
lbl9: TLabel;
edt1: TEdit;
lbl10: TLabel;
procedure
tmr1Timer(Sender: TObject);
procedure
btn1Click(Sender: TObject);
procedure
btn2Click(Sender: TObject);
private
public
end
;
var
Form1: TForm1;
implementation
{$R *.dfm}
function
HostToIP(name:
string
;
var
Ip:
string
):
Boolean
;
var
wsdata : TWSAData;
hostName :
array
[
0..255
]
of
char
;
hostEnt : PHostEnt;
addr
:
PChar
;
begin
WSAStartup (
$0101
, wsdata);
try
gethostname (hostName, sizeof (hostName));
StrPCopy(hostName, name);
hostEnt := gethostbyname (hostName);
if
Assigned (hostEnt)
then
if
Assigned (hostEnt^.h_addr_list)
then
begin
addr
:= hostEnt^.h_addr_list^;
if
Assigned (
addr
)
then
begin
IP := Format (
'%d.%d.%d.%d'
, [
byte
(
addr
[
0
]),
byte
(
addr
[
1
]),
byte
(
addr
[
2
]),
byte
(
addr
[
3
])]);
Result :=
True
;
end
else
Result :=
False
;
end
else
Result :=
False
else
begin
Result :=
False
;
end
;
finally
WSACleanup;
end
end
;
procedure
TForm1
.
tmr1Timer(Sender: TObject);
var
IP:
string
;
IPS:
string
;
outfile: TextFile;
begin
AssignFile(outfile,
'c:\outfile.txt'
);
Rewrite(outfile);
edt1
.
Text:=FormatDateTime(
'dd.mm.yy hh:mm:ss'
,Now());
HostToIp(edt2
.
Text, IP);
lbl1
.
Caption := IP;
Sleep(
10000
);
if
lbl1
.
Caption =
''
then
begin
lbl5
.
Visible:=
False
;
lbl2
.
Visible:=
True
;
writeln
(outfile, edt1
.
Text + #
13
#
10
);
CloseFile(outfile);
end
else
begin
lbl5
.
Visible:=
True
;
lbl2
.
Visible:=
False
;
end
;
HostToIp(
'google.com'
, IPS);
lbl7
.
Caption := IPS;
Sleep(
10000
);
if
lbl7
.
Caption =
''
then
begin
lbl8
.
Visible:=
False
;
lbl9
.
Visible:=
True
;
end
else
begin
lbl8
.
Visible:=
True
;
lbl9
.
Visible:=
False
;
end
;
end
;
procedure
TForm1
.
btn1Click(Sender: TObject);
begin
tmr1
.
Enabled:=
True
;
btn1
.
Visible:=
False
;
btn2
.
Visible:=
True
;
end
;
procedure
TForm1
.
btn2Click(Sender: TObject);
begin
tmr1
.
Enabled:=
False
;
btn1
.
Visible:=
True
;
btn2
.
Visible:=
False
;
lbl5
.
Visible:=
False
;
lbl2
.
Visible:=
False
;
lbl8
.
Visible:=
False
;
lbl9
.
Visible:=
False
;
end
;
end
.