博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
delphi 域名转ip并判断ip是否可以联通
阅读量:5149 次
发布时间:2019-06-13

本文共 3295 字,大约阅读时间需要 10 分钟。

unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls,WinSock;typeTForm1 = class(TForm)Button1: TButton;Button2: TButton;Edit1: TEdit;Edit2: TEdit;procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);private{
Private declarations }public{
Public declarations }end;varForm1: TForm1;implementation{
$R *.dfm}function PingHost(HostIP: String): Boolean;typePIPOptionInformation = ^TIPOptionInformation;TIPOptionInformation = packed recordTTL: Byte;TOS: Byte;Flags: Byte;OptionsSize: Byte;OptionsData: PChar;end;PIcmpEchoReply = ^TIcmpEchoReply;TIcmpEchoReply = packed recordAddress: DWORD;Status: DWORD;RTT: DWORD;DataSize: Word;Reserved: Word;Data: Pointer;Options: TIPOptionInformation;end;TIcmpCreateFile = function: THandle; stdcall;TIcmpCloseHandle = function(IcmpHandle: THandle): Boolean; stdcall;TIcmpSendEcho = function(IcmpHandle:THandle;DestinationAddress: DWORD;RequestData: Pointer;RequestSize: Word;RequestOptions: PIPOptionInformation;ReplyBuffer: Pointer;ReplySize: DWord;Timeout: DWord): DWord; stdcall;varhICMP :THandle;hICMPdll :THandle;IcmpCreateFile :TIcmpCreateFile;IcmpCloseHandle :TIcmpCloseHandle;IcmpSendEcho :TIcmpSendEcho;pIPE :PIcmpEchoReply;// ICMP Echo reply bufferFIPAddress :DWORD;FSize :DWORD;FTimeOut :DWORD;BufferSize :DWORD;pReqData,pRevData:PChar;MyString:string;beginResult :=False;hICMPdll :=LoadLibrary('icmp.dll');if hICMPdll=0 then exit;@ICMPCreateFile :=GetProcAddress(hICMPdll,'IcmpCreateFile');@IcmpCloseHandle :=GetProcAddress(hICMPdll,'IcmpCloseHandle');@IcmpSendEcho :=GetProcAddress(hICMPdll,'IcmpSendEcho');hICMP :=IcmpCreateFile;if (hICMP=INVALID_HANDLE_VALUE)then exit;FIPAddress :=inet_addr(PChar(HostIP));MyString :='Hello,World'; //send data bufferpReqData :=PChar(MyString);FSize :=40; //receive data bufferBufferSize :=SizeOf(TICMPEchoReply)+FSize;GetMem(pIPE,BufferSize);FillChar(pIPE^,SizeOf(pIPE^),0);GetMem(pRevData,FSize);pIPE^.Data :=pRevData;FTimeOut :=1000;tryResult :=IcmpSendEcho(hICMP,FIPAddress,pReqData,Length(MyString),nil,pIPE,BufferSize,FTimeOut)>0;finallyIcmpCloseHandle(hICMP);FreeLibrary(hICMPdll);FreeMem(pRevData);FreeMem(pIPE);end;end;function HostToIP(Name: string; var Ip: string): Boolean;varwsdata : TWSAData;hostName : array [0..255] of char;hostEnt : PHostEnt;addr : PChar;beginWSAStartup ($0101, wsdata);trygethostname (hostName, sizeof (hostName));StrPCopy(hostName, Name);hostEnt := gethostbyname (hostName);if Assigned (hostEnt) thenif Assigned (hostEnt^.h_addr_list) then beginaddr := hostEnt^.h_addr_list^;if Assigned (addr) then beginIP := Format ('%d.%d.%d.%d', [byte (addr [0]),byte (addr [1]), byte (addr [2]), byte (addr [3])]);Result := True;endelseResult := False;endelseResult := Falseelse beginResult := False;end;finallyWSACleanup;endend;procedure TForm1.Button1Click(Sender: TObject);varIP:String;flag:Boolean;begin//IP:='123.125.114.118';IP:=edit2.text;flag:=PingHost(IP);if flag=true thenMessageBox(0,'ping1','通路',MB_ICONASTERISK and MB_ICONINFORMATION)elseMessageBox(0,'ping2','断路',MB_ICONASTERISK and MB_ICONINFORMATION);end;procedure TForm1.Button2Click(Sender: TObject);varhqw:string;beginHostToIP(edit1.text,hqw);edit2.text:=hqw;end;end.

 

转载于:https://www.cnblogs.com/yzryc/p/6402056.html

你可能感兴趣的文章
mysql触发器
查看>>
淌淌淌
查看>>
web页面实现指定区域打印功能
查看>>
win10每次开机都显示“你的硬件设置已更改,请重启电脑……”的解决办法
查看>>
macOS10.12允许所有来源设置
查看>>
C++有关 const & 内敛 & 友元&静态成员那些事
查看>>
函数积累
查看>>
python搜索引擎(转)
查看>>
关于height,line-height导致的样式混乱的问题
查看>>
《SEO实战密码》读后一点感受
查看>>
bzoj 4815 [Cqoi2017]小Q的表格——反演+分块
查看>>
Swift 入门之简单语法(六)
查看>>
shim和polyfill有什么区别
查看>>
Failed to load the JNI shared library “E:/2000/Java/JDK6/bin/..jre/bin/client/jvm.dll
查看>>
〖Python〗-- IO多路复用
查看>>
栈(括号匹配)
查看>>
Java学习 · 初识 面向对象深入一
查看>>
源代码如何管理
查看>>
vue怎么将一个组件引入另一个组件?
查看>>
bzoj1040: [ZJOI2008]骑士
查看>>