Jump to content

IcmpSendEcho - poor example


Recommended Posts

;=============================================================================================
Func ycmChk_ICMP( $iLinA , $sUrlA = "211.216.50.150" , $sStrA = "" , $iTimeIn = 250 )
    Local $hWndA = 0

    Local $iChkA

    If StringLen( $sStrA ) == 0 Then
        $sStrA = TimerInit()
    EndIf

    If ycmIs_RANGE( $iTimeIn , 50 , 5000 ) == 0 Then
        Return ycmSet_ERR( $iLinA , @ScriptLineNumber , 0 , $iTimeIn )
    EndIf

    If ycmAPI_IcmpCreateFile( $iLinA , $hWndA ) == 0 Then
        Return 0
    EndIf

    $iChkA = ycmAPI_IcmpSendEcho( $iLinA , $hWndA , $sUrlA , $sStrA , $iTimeIn )

    ycmAPI_IcmpCloseHandle( $iLinA , $hWndA )

    If $iChkA == 0 Then
        Return 0
    Else
        Return 1
    EndIf
EndFunc


;=============================================================================================
Func ycmAPI_IcmpCloseHandle( $iLinA , ByRef $hWndA )
    Local $aDllW

    $aDllW = DllCall( $ah_Dll_Iphlpapi , "int" , "IcmpCloseHandle" , "handle" , $hWndA )
        ; BOOL IcmpCloseHandle(
        ;   __in  HANDLE IcmpHandle
        ; );
    If ycmIs_ERR( $iLinA , @ScriptLineNumber , $aDllW , 0 , 1 ) == 1 Then
        Return 0
    Else
        Return 1
    EndIf
EndFunc


;=============================================================================================
Func ycmAPI_IcmpCreateFile( $iLinA , ByRef $hWndA )
    Local $aDllW

    If Number( $hWndA ) <> 0 Or $hWndA > 0 Then
        ycmAPI_IcmpCloseHandle( $iLinA , $hWndA )
    EndIf

    $aDllW = DllCall( $ah_Dll_Iphlpapi , "handle" , "IcmpCreateFile" )
        ; HANDLE IcmpCreateFile(void);
    If ycmIs_ERR( $iLinA , @ScriptLineNumber , $aDllW , 0 , 1 ) == 1 Then
        Return 0
    Else
        $hWndA = $aDllW[0]

        Return 1
    EndIf
EndFunc


;=============================================================================================
Func ycmAPI_IcmpSendEcho( $iLinA , Const $hWndA , Const $sUrlA , Const $sStrA , Const $iTimeIn )
    Local $aDllW

    Local $aRetW[1][2] = [ [ 0 ] ]

    Local $aParW = StringSplit( $sUrlA , "." , 1 )

    If ycmIs_ARR( $aParW , 1 , 5 ) == 0 Then
        Return ycmSet_ERR( $iLinA , @ScriptLineNumber , 0 , $aParW )
    EndIf

    Local $iLenA = StringLen( $sStrA ) + 1
    Local $iAddr = 0

    $aDllW = DllCall( $ah_Dll_Ws2_32 , "ulong" , "inet_addr" , "str" , $sUrlA )
    If ycmIs_ERR( $iLinA , @ScriptLineNumber , $aDllW , 0 , 1 ) == 1 Then
        Return 0
    Else
        $iAddr = $aDllW[0]
    EndIf

    Local $tBufA = DllStructCreate( "BYTE Ttl; BYTE Tos; BYTE Flags; BYTE OptionsSize; ptr OptionsData" )
        ; typedef struct ip_option_information {
        ;   UCHAR  Ttl;
        ;   UCHAR  Tos;
        ;   UCHAR  Flags;
        ;   UCHAR  OptionsSize;
        ;   PUCHAR OptionsData;
        ; } IP_OPTION_INFORMATION, *PIP_OPTION_INFORMATION;

    DllStructSetData( $tBufA , "Ttl" , 255 )
    DllStructSetData( $tBufA , "Tos" , 0 )
    DllStructSetData( $tBufA , "Flags" , 0x2 )
        ; 0x01 IP_FLAG_REVERSE This value causes the IP packet to add in an IP routing header with the source. This value is only applicable on Windows Vista and later.
        ; 0x02 IP_FLAG_DF   This value indicates that the packet should not be fragmented.
    DllStructSetData( $tBufA , "OptionsSize" , 0 )
    DllStructSetData( $tBufA , "OptionsData" , 0 )

    Local $tBufB = DllStructCreate( "ulong Address; ulong Status; ulong RoundTripTime; ushort DataSize; ushort Reserved; char[260]; ptr" )
        ; typedef struct icmp_echo_reply {
        ;   IPAddr                      Address;
        ;   ULONG                       Status;
        ;   ULONG                       RoundTripTime;
        ;   USHORT                      DataSize;
        ;   USHORT                      Reserved;
        ;   PVOID                       Data;
        ;   struct ip_option_information Options;
        ; } ICMP_ECHO_REPLY, *PICMP_ECHO_REPLY;

    DllStructSetData( $tBufB , 7 , DllStructGetPtr( $tBufA ) )

    $aDllW = DllCall( $ah_Dll_Iphlpapi , "dword" , "IcmpSendEcho" , "handle" , $hWndA , "ulong" , $iAddr , "str" , $sStrA , "word" , $iLenA , "ptr" , DllStructGetPtr( $tBufA ) , "ptr" , DllStructGetPtr( $tBufB ) , "dword" , DllStructGetSize( $tBufB ) , "dword" , $iTimeIn )
        ; DWORD IcmpSendEcho(
        ;   __in    HANDLE IcmpHandle,
        ;   __in    IPAddr DestinationAddress,
        ;   __in    LPVOID RequestData,
        ;   __in    WORD RequestSize,
        ;   __in    PIP_OPTION_INFORMATION RequestOptions,
        ;   __inout  LPVOID ReplyBuffer,
        ;   __in    DWORD ReplySize,
        ;   __in    DWORD Timeout
        ; );

    ycmArr_AddA( $aRetW , "Ttl" , DllStructGetData( $tBufA , "Ttl" ) )
    ycmArr_AddA( $aRetW , "Tos" , DllStructGetData( $tBufA , "Tos" ) )
    ycmArr_AddA( $aRetW , "Flags" , DllStructGetData( $tBufA , "Flags" ) )
    ycmArr_AddA( $aRetW , "OptionsSize" , DllStructGetData( $tBufA , "OptionsSize" ) )
    ycmArr_AddA( $aRetW , "OptionsData" , DllStructGetData( $tBufA , "OptionsData" ) )

    ycmArr_AddA( $aRetW , "Address" , DllStructGetData( $tBufB , "Address" ) )
    ycmArr_AddA( $aRetW , "Status" , DllStructGetData( $tBufB , "Status" ) )
    ycmArr_AddA( $aRetW , "RoundTripTime" , DllStructGetData( $tBufB , "RoundTripTime" ) )
    ycmArr_AddA( $aRetW , "DataSize" , DllStructGetData( $tBufB , "DataSize" ) )
    ycmArr_AddA( $aRetW , "Reserved" , DllStructGetData( $tBufB , "Reserved" ) )
    ycmArr_AddA( $aRetW , "Data" , DllStructGetData( $tBufB , "Data" ) )
    ycmArr_AddA( $aRetW , "Options" , DllStructGetData( $tBufB , "Options" ) )

    $aRetW[0][0] = "HOST"
    $aRetW[0][1] = $sUrlA

    $tBufB = 0
    $tBufA = 0

    If ycmIs_ERR( $iLinA , @ScriptLineNumber , $aDllW , 0 , 1 ) == 1 Then
        ycmLog_THIS( $iLinA , "ycmAPI_IcmpSendEcho() ERR" , ycmGet_TYP( $aRetW , "RET" ) )

        Return 0
    Else
        ycmLog_THIS( $iLinA , "ycmAPI_IcmpSendEcho() O.k" , ycmGet_TYP( $aRetW , "RET" ) )

        Return $aRetW[3][1]
    EndIf
EndFunc

○ 10:14:03[12975][0|0] ycmAPI_IcmpSendEcho() O.k

RET|A13:00[0:S4[HOST] 1:S14[211.216.50.150]]

RET|A13:01[0:S3[Ttl] 1:I3[ 255]]

RET|A13:02[0:S3[Tos] 1:I1[ 0]]

RET|A13:03[0:S5[Flags] 1:I1[ 2]]

RET|A13:04[0:S11[OptionsSize] 1:I1[ 0]]

RET|A13:05[0:S11[OptionsData] 1:P4[00000000]]

RET|A13:06[0:S7[Address] 1:M4[9632D8D3]]

RET|A13:07[0:S6[status] 1:L1[ 0]]

RET|A13:08[0:S13[RoundTripTime] 1:L2[ 11]]

RET|A13:09[0:S8[DataSize] 1:I2[ 18]]

RET|A13:10[0:S8[Reserved] 1:I1[ 0]]

RET|A13:11[0:S4[Data] 1:I1[ 0]]

RET|A13:12[0:S7[Options] 1:I1[ 0]]

Edited by DllParse
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...