to inbreak
留下你的QQ和mail
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, winsock;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetHostFromIP(ip: string): string;
var
sData: TWSAData;
h: PHostEnt;
p: TInAddr;
begin
Result := '';
//CheckIP;//检查IP是否合法,你自己写
// if (not CheckIP) or (WSAStartup($101, sData)) = SOCKET_ERROR then Exit;
if WSAStartup($101, sData) = SOCKET_ERROR then Exit;
p.S_addr := inet_addr(PChar(ip));
h := gethostbyaddr(@p.S_addr, 4, AF_INET);
if h <> nil then Result := h^.h_name;
WSACleanup;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if GetHostFromIP('192.168.0.1') = '' then
showmessage('没有这个IP地址')
else
showmessage('有这个IP地址');
end;
end.