Winpcap UDF Hilfe

  • Spoiler anzeigen
    [autoit]

    #include <Winpcap.au3>
    $data="6162636465666768696a6b6c6d6e6f7071727374757677616263646566676869"
    $totlength = "00" & hex(4 + 20 + 4 + BinaryLen($data)/2,2)

    [/autoit] [autoit][/autoit] [autoit]

    $winpcap=_PcapSetup() ; initialize winpcap
    $pcap_devices=_PcapGetDeviceList() ; get devices list
    $pcap=_PcapStartCapture($pcap_devices[0][0]) ; my interface

    [/autoit] [autoit][/autoit] [autoit]

    ;Ethernet header
    $broadcastmac="001451709b47" ; MAC from GW
    $mymac=StringReplace($pcap_devices[0][6],":","") ; my mac address in hex
    $ethertype="0800" ; IP

    [/autoit] [autoit][/autoit] [autoit]

    $ethernetheader=$broadcastmac&$mymac&$ethertype ; stick together to a binary string !

    [/autoit] [autoit][/autoit] [autoit]

    ;IP header
    $version = "4"
    $headerlength = "5"
    $tos = "00"
    $ident = "1234"
    $ffo = "4000"
    $ttl = "80"
    $prot = "01"
    $sourceaddress = IPtoHex($pcap_devices[0][7])
    $destaddress = IPtoHex("209.85.129.105") ;google.com
    ;$totlength = "003c"

    [/autoit] [autoit][/autoit] [autoit]

    $crc = Hex(_PcapIpCheckSum("0x"&$ethernetheader&$version&$headerlength&$tos&$totlength&$ident&$ffo&$ttl&$prot&"0000"&$sourceaddress&$destaddress),4)

    [/autoit] [autoit][/autoit] [autoit]

    $ippacket = $ethernetheader&$version&$headerlength&$tos&$totlength&$ident&$ffo&$ttl&$prot&$crc&$sourceaddress&$destaddress

    [/autoit] [autoit][/autoit] [autoit]

    ;ICMP
    $type="08"
    $code="00"
    $identifier="0001"
    $seq="0001"
    ;$data="6162636465666768696a6b6c6d6e6f7071727374757677616263646566676869"
    $checksum = Hex(_PcapIcmpCheckSum("0x"&$ippacket&$type&$code&"0000"&$identifier&$seq&$data),4)

    [/autoit] [autoit][/autoit] [autoit]

    $ICMP = $type&$code&$checksum&$identifier&$seq&$data

    [/autoit] [autoit][/autoit] [autoit]

    $mypacket = "0x"&$ippacket&$type&$code&$checksum&$identifier&$seq&$data
    _PcapSendPacket($pcap,$mypacket) ; sends a valid packet

    [/autoit] [autoit][/autoit] [autoit]

    _PcapFree() ; close winpcap

    [/autoit] [autoit][/autoit] [autoit]

    Func IPtoHex($ip)
    dim $iphex
    $ip = StringSplit($ip,".")

    for $i = 1 to 4 Step 1
    $iphex &= Hex($ip[$i],2)
    Next

    return $iphex
    EndFunc

    [/autoit]

    Das ist ein Beispiel aus einem anderen Forum was bei mir nicht geht :D