Jump to content
Sign in to follow this  
Fabry

Packetx

Recommended Posts

Fabry, Have you figured out how to have it Send packets?

Like, ReSend captured packets?

Resend packets? like a router?

I will work on send.vbs example, but it's hard.

@JamesB

If get message error means you don't have PacketX installed. Remember you have to install also WinPcap.

@ Jmaleal

You inetend for World of Warcraft? See This

Edited by Fabry

A lan chat (Multilanguage)LanMuleFile transferTank gameTank 2 an online game[center]L'esperienza è il nome che tutti danno ai propri errori.Experience is the name everyone gives to their mistakes.Oscar Wilde[/center]

Share this post


Link to post
Share on other sites

I have problem with this code:

CODE
$oPktX.Adapter.SendPacket Array(&hFF, &hFF, &hFF, &hFF, &hFF, &hFF,_

CByte(HexToDec(Mid(sHWAddr,1,2))),_

CByte(HexToDec(Mid(sHWAddr,3,2))),_

CByte(HexToDec(Mid(sHWAddr,5,2))),_

CByte(HexToDec(Mid(sHWAddr,7,2))),_

CByte(HexToDec(Mid(sHWAddr,9,2))),_

CByte(HexToDec(Mid(sHWAddr,11,2))),_

&h08, &h06, &h00, &h01, _

&h08, &h00, &h06, &h04, &h00, &h01,_

CByte(HexToDec(Mid(sHWAddr,1,2))),_

CByte(HexToDec(Mid(sHWAddr,3,2))),_

CByte(HexToDec(Mid(sHWAddr,5,2))),_

CByte(HexToDec(Mid(sHWAddr,7,2))),_

CByte(HexToDec(Mid(sHWAddr,9,2))),_

CByte(HexToDec(Mid(sHWAddr,11,2))),_

CByte(aIPAddr(0)),_

CByte(aIPAddr(1)),_

CByte(aIPAddr(2)),_

CByte(aIPAddr(3)),_

&h00, &h00, &h00, &h00, &h00, &h00,_

CByte(aIPReso(0)),_

CByte(aIPReso(1)),_

CByte(aIPReso(2)),_

CByte(aIPReso(3)),_

&h00, &h00, &h00, &h00, &h00, &h00,_

&h00, &h00, &h00, &h00, &h00, &h00,_

&h00, &h00, &h00, &h00, &h00, &h00), 100


A lan chat (Multilanguage)LanMuleFile transferTank gameTank 2 an online game[center]L'esperienza è il nome che tutti danno ai propri errori.Experience is the name everyone gives to their mistakes.Oscar Wilde[/center]

Share this post


Link to post
Share on other sites

I finished to translate example "Capture":

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.4.9
    Author:         Fabry
    
    Script Function:
    Sniffer fo network
    
#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
;~ // Constants
#include<String.au3>
Const $PktXPacketTypePromiscuous = 0x0020
Const $PktXLinkType802_3 = 1
Const $PktXLinkType802_5 = 2
Const $PktXLinkTypeFddi = 3
Const $PktXLinkTypeWan = 4
Const $PktXLinkTypeLocalTalk = 5
Const $PktXLinkTypeDix = 6
Const $PktXLinkTypeArcnetRaw = 7
Const $PktXLinkTypeArcnet878_2 = 8
Const $PktXLinkTypeAtm = 9
Const $PktXLinkTypeWirelessWan = 10
Const $PktXModeCapture = 1

; Protocol types
Const $PktXProtocolTypeEthernet = 1
Const $PktXProtocolTypeIp = 2
Const $PktXProtocolTypeUdp = 3
Const $PktXProtocolTypeTcp = 4

;~ // Create PackeX object
Global $oPktX = ObjCreate("PktX.PacketX")
If Not IsObj($oPktX) Then MsgBox(0, "ERROR", "No Object")
$EventObject = ObjEvent($oPktX, "PacketX_")

;############   Select network adapter ###########  replace 2007-09-25

;~ // Display network adapters
Dim $info
For $i = 1 To $oPktX.Adapters.Count
    If $oPktX.Adapters ($i).IsGood Then
        $info &= "(" & $i & ") " & $oPktX.Adapters ($i).Description & @CRLF
        PrintAdapter($oPktX.Adapters ($i))
    EndIf
Next

;Enter Adapter #
Dim $SelAdapter = $oPktX.Adapters.Count  ;default: last adapter #
While 1
    Local $SelAdapter = InputBox("Choose adapter Number", $info, $oPktX.Adapters.Count)
    If @error > 0 Then Exit 99
    If $SelAdapter >= 1 And $SelAdapter <= $oPktX.Adapters.Count Then ExitLoop
    MsgBox(0+16, "Error", "The Selected Number '"&$SelAdapter&"' is not in range")
WEnd

; Select network adapter
$oPktX.Adapter = $oPktX.Adapters ($SelAdapter)

;####### End Modification #######

;~ PrintAdapter($oPktX.Adapter)
; Capture buffer parameters
$oPktX.Adapter.BuffSize = 256 * 1024 ; 256 KB
$oPktX.Adapter.BuffMinToCopy = 0

; Hardware filter and capture mode
$oPktX.Adapter.HWFilter = $PktXPacketTypePromiscuous
$oPktX.Adapter.Mode = $PktXModeCapture

; Start capture
$oPktX.Start
$begin = TimerInit()
While TimerDiff($begin) < 60000
    Sleep(1)
WEnd
$oPktX.Stop

PrintStats($oPktX.Adapter)

; Packet event handler
Func PacketX_OnPacket($oPacket)
    PrintHead($oPacket)
    PrintData($oPacket)
EndFunc   ;==>PacketX_OnPacket
Func PrintAdapter($oAdapter)
    ConsoleWrite("Device name is " & $oAdapter.Device & @LF)
    ConsoleWrite("Link type is ")
    Switch $oAdapter.LinkType
        Case $PktXLinkType802_3
            ConsoleWrite("Ethernet (802.3)" & @LF)
        Case $PktXLinkType802_5
            ConsoleWrite("Token Ring (802.5)" & @LF)
        Case $PktXLinkTypeFddi
            ConsoleWrite("FDDI" & @LF)
        Case $PktXLinkTypeWan
            ConsoleWrite("WAN" & @LF)
        Case $PktXLinkTypeLocalTalk
            ConsoleWrite("LocalTalk" & @LF)
        Case $PktXLinkTypeDix
            ConsoleWrite("DIX" & @LF)
        Case $PktXLinkTypeArcnetRaw
            ConsoleWrite("ARCNET (raw)" & @LF)
        Case $PktXLinkTypeArcnet878_2
            ConsoleWrite("ARCNET (878.2)" & @LF)
        Case $PktXLinkTypeAtm
            ConsoleWrite("ATM" & @LF)
        Case $PktXLinkTypeWirelessWan
            ConsoleWrite("NdisWirelessXxx media" & @LF)
        Case Else
            ConsoleWrite("Unknown!" & @LF)
    EndSwitch
    ConsoleWrite("Link speed is " & $oAdapter.LinkSpeed & " bps" & @LF)
;~      Consolewrite( "Network IP addres is " & $oAdapter.NetIP&@LF)
;~    Consolewrite( "Network mask is " & $oAdapter.NetMask&@LF)
    ConsoleWrite("HW address is " & $oAdapter.HWAddress & @LF)
EndFunc   ;==>PrintAdapter

Func PrintHead($oPacket)
    local $type
    Switch $oPacket.Protocol
        Case $PktXProtocolTypeEthernet
        $type='Eth'     
        Case $PktXProtocolTypeIp
        $type='Ip'  
        Case $PktXProtocolTypeUdp
        $type='UDP' 
        Case $PktXProtocolTypeTcp
    $type='TCP' 
    EndSwitch
    ConsoleWrite("----------------------- Packet Header ---------------------" & @LF)
    ConsoleWrite("Original size " & $oPacket.OriginalSize & " bytes" & @LF)
    ConsoleWrite("Capture size " & $oPacket.DataSize & " bytes" & @LF)
    ConsoleWrite("Capture time " & $oPacket.TimeSec & " (number of seconds from 1/1/1970)" & @LF)
    ConsoleWrite("Capture microseconds " & $oPacket.TimeUSec & @LF)
    ConsoleWrite("Capture date " & $oPacket.Date & " (system date and time)" & @LF)
    ConsoleWrite('Protocol: ' & $type & @LF)
    ConsoleWrite('From ' & $oPacket.SourceIpAddress & ':' & $oPacket.Sourceport & ' To ' & $oPacket.DestIpAddress & ':' & $oPacket.DestPort & @LF)
EndFunc   ;==>PrintHead


;############   Show Packet Data  ###########  replace 2007-09-25

Func PrintData($oPacket)
    ConsoleWrite("----------------------- Packet Data -----------------------" & @LF)
    Local $string = ""
    For $bByte In $oPacket.Data
        $string &= Chr($bByte)
    Next
    ConsoleWrite(_HexDump2($string) & @LF)
EndFunc   ;==>PrintData

;####### End Modification #######


Func PrintStats($oAdapter)
    ConsoleWrite("------------------- Capture Statistics --------------------" & @LF)
    ConsoleWrite("Packets received " & $oAdapter.PacketsRecv & @LF)
    ConsoleWrite("Packets lost " & $oAdapter.PacketsLost & @LF)
EndFunc   ;==>PrintStats



;############   HEXDUMP  ###########  new 2007-09-25

#include <string.au3>       ; only needed for _HexDump(..)

;=====================================================================================================
; Function:         _HexDump($sHexString[,$iFixOffset][,$iBytePerLine][,$bUseCheck])
;                   This is only a wrapper for calling the function _HexDump2()
; Description:      Dumping a hexstring - makes a HEX & ASCII dump like 
;                      00000000: 48 45 58 3A 20 30 78 41 62 63 44                HEX: 0xAbcD
;                   The string can starting with  0x or &h  as signing a hexstring
;                      0x1234ab  or  &H1234AB  is the same like this   1234ab
; Parameter(s):     $sHexString - The Hexstring to dump. The format is like _StringToHex("abc"),
;                                 default ""
;                   $iFixOffset - (optional) Start dumping at this number, default 0.
;                   $iBytePerLine - (optional) set the number of Hexbytes per line of dump, default 16.
;                   $bUseCheck - (optional) True: do some checks on input, (default) False: do not.
;                                If FALSE, an error dumps  "00000000: 2D 31           -1"
; Requirement(s):   <string.au3>
; Return Value(s):  On Success - Returns a string containing the dump.
;                   On Failure - Returns a discribtion of the error
;                   @Error - 0 = No error.
;                           -1 = Length of the hexstring is not even.
;                           -2 = String is not a valid hexstring.
;                           -3 = Offset is not an Integer.
;                           -4 = Offset must be >= 0 and positive Integer
;                           -5 = Byte/line must be > 0 and positive Integer
;                           -6 = Byte/line must fit to x mod 4 == 0
; Author(s):        ReCoder
; Note(s):
; Examples:     _HexDump("AABBcc3039AbCDeF")
;               returns    000000: AA BB CC 30 39 AB CD EF              ...09...
;=====================================================================================================
Func _HexDump($sHexString = "", $iFixOffset = 0, $iBytePerLine = 16, $bUseCheck = False)
    ; Do some checks
    If $bUseCheck Then
        ; Reformat Hexstring
        ;     Delete 0x or &h at startposition of the string, than remove spaces,
        $sHexString = StringRegExpReplace($sHexString, "^0[xX]|^&[hH]", "", 1)
        $sHexString = StringReplace($sHexString, " ", "")
        ; Check for valid Hexstring.
        If Not StringIsXDigit($sHexString) Then Return _
            SetError(-2, -2, "Not a valid HEX string.")
        ; Check for valid length of the string.
        If BitAND(StringLen($sHexString), 0x01) = 1 Then _
            Return SetError(-1, -1, "Hexstring length must be even, length is '"& _
            StringLen($sHexString)&"'.")
    EndIf
    Return _HexDump2(_HexToString($sHexString), $iFixOffset, $iBytePerLine, $bUseCheck)
EndFunc

;=====================================================================================================
; Function:         _HexDump2($sAscString[,$iFixOffset][,$iBytePerLine][,$bUseCheck])
; Description:      Dumping a ASCII string - makes a HEX & ASCII dump like 
;                      00000000: 48 45 58 3A 20 30 78 41 62 63 44                HEX: 0xAbcD
; Parameter(s):     $sAscString - The ASCII string to dump. The format is 8Bit ASCII, no realy 
;                   Unicode support, default ""
;                   $iFixOffset - (optional) Start dumping at this number, default 0.
;                                 The Offset must be an Integer and 0 or higher
;                   $iBytePerLine - (optional) set the number of Hexbytes per line of dump, default 16.
;                   $bUseCheck - (optional) True: do some checks on input, (default) False: do not.
;                                If FALSE, an error dumps  "00000000: 2D 31           -1"
; Requirement(s):   None.
; Return Value(s):  On Success - Returns a string containing the dump.
;                   On Failure - Returns a discribtion of the error
;                   @Error - 0 = No error.
;                           -1 = Length of the hexstring is not even.
;                           -2 = String is not a valid hexstring.
;                           -3 = Offset is not an Integer.
;                           -4 = Offset must be 0 or positive Integer
;                           -5 = Byte/line must be > 0
;                           -6 = Byte/line must fit to x mod 4 == 0
; Author(s):        ReCoder
; Note(s):
; Examples:     _HexDump2("Hallo :)")
;               returns    00000000: 48 61 6C 6C 6F 20 3A 29          Hallo :)
;=====================================================================================================
Func _HexDump2($sAscString = "", $iFixOffset = 0, $iBytePerLine = 16, $bUseCheck = False)
    ; Do some checks
    If $bUseCheck Then
        ; Check FixOffset
        If Not IsInt($iFixOffset) Then Return SetError(-3, -3, "Offset must be Integer.")
        If $iFixOffset < 0 Then Return SetError(-4, -4, "Offset must be >= 0.")
        ; Check BytePerLine
        If $iBytePerLine < 0 Then Return SetError(-5, -5, "Byte/line must be > 0.")
        If Mod($iBytePerLine,4) <> 0 Then Return SetError(-6, -6, "Byte/line must fit to x mod 4 == 0.")
    EndIf
    
    ; Check for empty String. --> Dump only Offset, no data
    If $sAscString = "" Then Return Hex($iFixOffset,8) & ": " & @CRLF   ; Nothing to do
    
    ; Calculate Dump Parameters
    Local $iHexCharCnt = StringLen($sAscString) ; Stringlength
    Local $iOffset = $iFixOffset                ; Offset, starts with $iFixOffset
    Local $iInLoopCnt = 0                       ; Act. Bytes per line
    Local $sAscii = ""                          ; ASCII dump per line "ABC.02...."
    Local $sHex = ""                            ; HEX dump per line "AB 0D CA ...."
    Local $sDump = ""                           ; Dump per Line "OFFSET: HEXdump ASCIIdump"
    Local $sDumpReturn = ""                     ; The whole dump string to return
    
    ; Looping over string
    For $i = 1 To $iHexCharCnt
        ; Calculate counter
        $iInLoopCnt += 1
        ; Assemble per line dump
        Local $sChar = StringMid($sAscString, $i, 1) ; Take one char and ...
        $sHex &= StringUpper(Hex(Asc($sChar),2)) & " "   ; Build HEX dump "AB 0D CA ..."
        If Not StringIsASCII($sChar) Then $sChar = "."   ; Check for NonPrintable char
        $sAscii &= $sChar                       ; Build ASCII dump "ABCD..."
        ; check for end of dump line
        If $iInLoopCnt >= $iBytePerLine Then    ; New line after $iBytePerLine Bytes
            $sDump = Hex($iOffset,8) & ": " & $sHex & $sAscii & @CRLF ; Build line of dump
            $sDumpReturn &= $sDump              ; Build whole dump string
            ; Reset "per line" Parameter
            $iOffset += $iInLoopCnt             ; !! $iInLoopCnt := $iBytePerLine
            $iInLoopCnt = 0                     ; Act. Bytes per line
            $sAscii = ""                        ; ASCII dump per line "ABC.02...."
            $sHex = ""                          ; HEX dump per line "AB 0D CA ...."
            $sDump = ""                         ; Dump per Line "OFFSET: HEXdump ASCIIdump"
        EndIf
    Next
    ; Check if returnstring is incomplete
    If $iInLoopCnt > 0 Then
        For $ii = 1 To $iBytePerLine-$iInLoopCnt
            $sHex &= "   "   ; Appends HEX with SPACE
        Next
        $sDump = Hex($iOffset,8) & ": " & $sHex & $sAscii & @CRLF ; Build line of dump
        $sDumpReturn &= $sDump              ; Build whole dump string
    EndIf
    Return $sDumpReturn
EndFunc

;####### End Modification #######
Hi,

I always searched for this solution, because my porting don't working.

So, thanks for this code. You've done a good job.

It's basicly to understand the PacketX component.

Infos about PacketX-->Packet class

http://www.beesync.com/packetx/docs/html/i...PktXPacket.html

and the original PacketX example

http://www.beesync.com/packetx/docs/html/C...bs-example.html

I do some modifications, because it was not possible to select a network adapter and I changed the HEXDUMP of packet data.

PS. Don't forget to install PacketX on your PC <-- It's the answer for many questions :)

So try it and have fun.

Edited by ReCoder

Share this post


Link to post
Share on other sites

The PacketX is commercial software and you need to purchase it. Have anyone tried with the WinPCap yet ?

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...