Jump to content

PacketX


Recommended Posts

I am trying to convert this vb code that deals with packetx. Here is the code...

CODE
'///////////////////////////////////////////////////////////////////////////////

'// File: Send.js

'//

'// Description: This script demonstrates how to send packets

'//

'// Notes: Run the script from command line using the cscript.exe program

'//

'// Created: May 10, 2004

'//

'// Copyright © 2000-2004 BeeSync Technologies.

'///////////////////////////////////////////////////////////////////////////////

'// Create PacketX instance

Set oPktX = WScript.CreateObject("PktX.PacketX")

'// Display network adapters

For i = 1 To oPktX.Adapters.Count

If oPktX.Adapters(i).IsGood Then

WScript.Echo "(" & i & ") " & RTrim(LTrim(oPktX.Adapters(i).Description))

End If

Next

'// Select network adapter

oPktX.Adapter = Nothing

While oPktX.Adapter Is Nothing

WScript.StdOut.Write "Choose adapter#"

On Error Resume Next

oPktX.Adapter = oPktX.Adapters(RTrim(LTrim(WScript.StdIn.ReadLine)))

On Error Goto 0

Wend

'// Get adapter hardware address and IP address

sHWAddr = oPktX.Adapter.HWAddress

sIPAddr = oPktX.Adapter.NetIP

sIPMask = oPktX.Adapter.NetMask

WScript.Echo "MAC Addr = " & sHWAddr

WScript.Echo "IP Addr = " & sIPAddr

WScript.Echo "IP Mask = " & sIPMask

'// Send ARP request for this IP address

sIPReso = "11.12.13.14"

aIPReso=Split(sIPReso, ".", -1, 1)

aIPAddr=Split(sIPAddr, ".", -1, 1)

'// You can use the following syntax to call the Adapter.SendPacket method

'//

'// 1. Send packet by reference (VT_BYREF|VT_VARIANT) as array of variants

'// oPktX.Adapter.SendPacket oPacket, 1

'//

'// 2. Send packet by value (VT_BYREF|VT_VARIANT|VT_ARRAY) as array of variants

'// oPktX.Adapter.SendPacket(oPacket)

'//

'// 3. Send packet directly (VT_VARIANT|VT_ARRAY) as array of variants

'// oPktX.Adapter.SendPacket Array(1,2,...,n)

'// Send 100 ARP requests

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

Function HexToDec(sByte)

For Counter=1 To Len(sByte)

Select Case Mid(sByte,Counter,1)

Case "0" HexToDec=HexToDec+0*(16^(Len(sByte)-Counter))

Case "1" HexToDec=HexToDec+1*(16^(Len(sByte)-Counter))

Case "2" HexToDec=HexToDec+2*(16^(Len(sByte)-Counter))

Case "3" HexToDec=HexToDec+3*(16^(Len(sByte)-Counter))

Case "4" HexToDec=HexToDec+4*(16^(Len(sByte)-Counter))

Case "5" HexToDec=HexToDec+5*(16^(Len(sByte)-Counter))

Case "6" HexToDec=HexToDec+6*(16^(Len(sByte)-Counter))

Case "7" HexToDec=HexToDec+7*(16^(Len(sByte)-Counter))

Case "8" HexToDec=HexToDec+8*(16^(Len(sByte)-Counter))

Case "9" HexToDec=HexToDec+9*(16^(Len(sByte)-Counter))

Case "A" HexToDec=HexToDec+10*(16^(Len(sByte)-Counter))

Case "B" HexToDec=HexToDec+11*(16^(Len(sByte)-Counter))

Case "C" HexToDec=HexToDec+12*(16^(Len(sByte)-Counter))

Case "D" HexToDec=HexToDec+13*(16^(Len(sByte)-Counter))

Case "E" HexToDec=HexToDec+14*(16^(Len(sByte)-Counter))

Case "F" HexToDec=HexToDec+15*(16^(Len(sByte)-Counter))

End Select

Next

End Function

Here is what I have converted.

#NoTrayIcon
#AutoIt3Wrapper_Change2CUI=y

#include <array.au3>

Global $oPktX = ObjCreate("PktX.PacketX")
If Not IsObj($oPktX) Then 
    MsgBox(0, "ERROR", "No Object")
    Exit
EndIf

For $i = 1 to $oPktX.Adapters.Count
    If $oPktX.Adapters($i).Isgood Then
        ConsoleWrite($i & ". " & $oPktX.Adapters($i).Description & @CRLF)
    EndIf
Next
ConsoleWrite("Choose Adapter: ")

$oPktX.Adapter = $oPktX.Adapters(Int(cmdRead()))

$sHWAddr = $oPktX.Adapter.HWAddress
ConsoleWrite("MAC Address = " & $sHWAddr & @CRLF)

$sIPMask = $oPktX.Adapter.NetMask
ConsoleWrite("IP  Mask = " & $sIPMask & @CRLF)

$sIPAddr = $oPktX.Adapter.NetIP
ConsoleWrite("IP  Address = " & $sIPAddr & @CRLF)

$sIPReso = "11.12.13.14"
$aIPReso = StringSplit($sIPReso, ".")
$aIPAddr = StringSplit($sIPAddr, ".")

Dim $aPacket[60] = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, _
      Int(Dec("0x" & StringMid($sHWAddr, 0, 2))), _
      Int(Dec("0x" & StringMid($sHWAddr, 2, 2))), _
      Int(Dec("0x" & StringMid($sHWAddr, 4, 2))), _
      Int(Dec("0x" & StringMid($sHWAddr, 6, 2))), _
      Int(Dec("0x" & StringMid($sHWAddr, 8, 2))), _
      Int(Dec("0x" & StringMid($sHWAddr, 10, 2))), _
      0x08, 0x06, 0x00, 0x01, _
      0x08, 0x00, 0x06, 0x04, 0x00, 0x01, _
      Int(Dec("0x" & StringMid($sHWAddr, 0, 2))), _
      Int(Dec("0x" & StringMid($sHWAddr, 2, 2))), _
      Int(Dec("0x" & StringMid($sHWAddr, 4, 2))), _
      Int(Dec("0x" & StringMid($sHWAddr, 6, 2))), _
      Int(Dec("0x" & StringMid($sHWAddr, 8, 2))), _
      Int(Dec("0x" & StringMid($sHWAddr, 10, 2))), _   
      Int($aIPAddr[0]), _
      Int($aIPAddr[1]), _
      Int($aIPAddr[2]), _
      Int($aIPAddr[3]), _
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, _
      Int($aIPReso[0]), _
      Int($aIPReso[1]), _
      Int($aIPReso[2]), _
      Int($aIPReso[3]), _
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, _
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, _
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
      
_ArrayDisplay($aPacket)
      
;$oPktX.Adapter.SendPacket($aPacket)      

Func cmdRead()
    Local $input = ""
    $file = FileOpen("con", 4)
    While 1
        $chr = FileRead($file, 1)
        If $chr = @LF Then ExitLoop
        $input &= BinaryToString($chr)
        Sleep(50)
    WEnd
    FileClose($file)
    $input = StringReplace($input, @CR, "")
    Return $input
EndFunc

When I run this I get an error when I try to get the NetIP or the Netmask. Windows says Data Execution Prevention stopped the programming from running. What does this mean and what can I do to fix it?

P.S. I am running windows vista x64.

Edited by SoulA
Link to comment
Share on other sites

Searching on Google gives this among many other things.

Wouldn't you have saved some time by searching?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...