• Delphi通过ICMP检测与远程主机连接


    { ping IP 地址(返回false or true) 2015-03-23}
    function PingHost(HostIP: String): Boolean;
    type
      PIPOptionInformation =  ^TIPOptionInformation;
      TIPOptionInformation = packed record
        TTL:Byte;
        TOS:Byte;
        Flags:Byte;
        OptionsSize:Byte;
        OptionsData:PChar;
      end;
    
      PIcmpEchoReply= ^TIcmpEchoReply;
      TIcmpEchoReply = packed record
        Address: 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;
    var
      hICMP:THandle;
      hICMPdll:THandle;
      IcmpCreateFile:TIcmpCreateFile;
      IcmpCloseHandle:TIcmpCloseHandle;
      IcmpSendEcho:TIcmpSendEcho;
      pIPE:PIcmpEchoReply;//   ICMP   Echo   reply   buffer
      FIPAddress:DWORD;
      FSize:DWORD;
      FTimeOut:DWORD;
      BufferSize:DWORD;
      pReqData,pRevData:PChar;
      MyString:string;
    begin   
      Result:=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   buffer
      pReqData:=PChar(MyString);
    
      FSize:=40;                                                 //receive   data   buffer
      BufferSize:=SizeOf(TICMPEchoReply)+FSize;
      GetMem(pIPE,BufferSize);   
      FillChar(pIPE^,SizeOf(pIPE^), 0);
      GetMem(pRevData,FSize);
      pIPE^.Data:=pRevData;
      FTimeOut:=500;
      try
        Result:=IcmpSendEcho(hICMP, FIPAddress,pReqData,
        Length(MyString),nil,pIPE,BufferSize,FTimeOut)>0;
      finally
        IcmpCloseHandle(hICMP);
        FreeLibrary(hICMPdll);
        FreeMem(pRevData);
        FreeMem(pIPE);
      end;
    end;
  • 相关阅读:
    (转)样本方差的期望
    (转)Python 字典排序
    曝光补偿
    python判断字符串是否包含子字符串
    python requests接口测试 -----博客园串接口
    jmeter+ant+jenkins 搭建接口自动化测试
    TOMCAT闪退。cmd执行startup.bat保错:the CATALINA_HOME environment variable is not defined correctly
    selenium python自动化测试 ddt数据驱动
    jenkins到底如何拉取代码 如何部署的
    git 常用命令
  • 原文地址:https://www.cnblogs.com/tc310/p/4359887.html
Copyright © 2020-2023  润新知