Send.vbs

This example demonstrates how to send packets from VBScript.
See also:
PacketX , Adapter , SendPacket
00001 '
00002 '// File:         Send.js
00003 '//
00004 '// Description:  This script demonstrates how to send packets
00005 '//
00006 '// Notes:        Run the script from command line using the cscript.exe program
00007 '//
00008 '// Created:      May 10, 2004
00009 '//
00010 '// Copyright (c) 2000-2004 BeeSync Technologies.
00011 '
00012 
00013 '// Create PacketX instance
00014 Set oPktX = WScript.CreateObject("PktX.PacketX")
00015 
00016 '// Display network adapters
00017 For i = 1 To oPktX.Adapters.Count
00018   If oPktX.Adapters(i).IsGood Then
00019     WScript.Echo "(" & i & ") " & RTrim(LTrim(oPktX.Adapters(i).Description))
00020   End If
00021 Next
00022 
00023 '// Select network adapter
00024 oPktX.Adapter = Nothing
00025 While oPktX.Adapter Is Nothing
00026   WScript.StdOut.Write "Choose adapter#"
00027   On Error Resume Next
00028     oPktX.Adapter = oPktX.Adapters(RTrim(LTrim(WScript.StdIn.ReadLine)))
00029   On Error Goto 0
00030 Wend
00031 
00032 '// Get adapter hardware address and IP address
00033 sHWAddr = oPktX.Adapter.HWAddress
00034 sIPAddr = oPktX.Adapter.NetIP
00035 sIPMask = oPktX.Adapter.NetMask
00036 WScript.Echo "MAC Addr = " & sHWAddr
00037 WScript.Echo "IP  Addr = " & sIPAddr
00038 WScript.Echo "IP  Mask = " & sIPMask
00039 
00040 '// Send ARP request for this IP address
00041 sIPReso = "11.12.13.14"
00042 aIPReso=Split(sIPReso, ".", -1, 1)
00043 aIPAddr=Split(sIPAddr, ".", -1, 1)
00044 
00045 '// You can use the following syntax to call the Adapter.SendPacket method
00046 '//
00047 '// 1. Send packet by reference (VT_BYREF|VT_VARIANT) as array of variants
00048 '// oPktX.Adapter.SendPacket oPacket, 1
00049 '//
00050 '// 2. Send packet by value (VT_BYREF|VT_VARIANT|VT_ARRAY) as array of variants
00051 '// oPktX.Adapter.SendPacket(oPacket)
00052 '// 
00053 '// 3. Send packet directly (VT_VARIANT|VT_ARRAY) as array of variants
00054 '// oPktX.Adapter.SendPacket Array(1,2,...,n)
00055 
00056 '// Send 100 ARP requests
00057 oPktX.Adapter.SendPacket Array(&hFF, &hFF, &hFF, &hFF, &hFF, &hFF,_
00058       CByte(HexToDec(Mid(sHWAddr,1,2))),_
00059       CByte(HexToDec(Mid(sHWAddr,3,2))),_
00060       CByte(HexToDec(Mid(sHWAddr,5,2))),_
00061       CByte(HexToDec(Mid(sHWAddr,7,2))),_
00062       CByte(HexToDec(Mid(sHWAddr,9,2))),_
00063       CByte(HexToDec(Mid(sHWAddr,11,2))),_
00064       &h08, &h06, &h00, &h01, _
00065       &h08, &h00, &h06, &h04, &h00, &h01,_
00066       CByte(HexToDec(Mid(sHWAddr,1,2))),_
00067       CByte(HexToDec(Mid(sHWAddr,3,2))),_
00068       CByte(HexToDec(Mid(sHWAddr,5,2))),_
00069       CByte(HexToDec(Mid(sHWAddr,7,2))),_
00070       CByte(HexToDec(Mid(sHWAddr,9,2))),_
00071       CByte(HexToDec(Mid(sHWAddr,11,2))),_
00072       CByte(aIPAddr(0)),_
00073       CByte(aIPAddr(1)),_
00074       CByte(aIPAddr(2)),_
00075       CByte(aIPAddr(3)),_
00076       &h00, &h00, &h00, &h00, &h00, &h00,_
00077       CByte(aIPReso(0)),_
00078       CByte(aIPReso(1)),_
00079       CByte(aIPReso(2)),_
00080       CByte(aIPReso(3)),_
00081       &h00, &h00, &h00, &h00, &h00, &h00,_
00082       &h00, &h00, &h00, &h00, &h00, &h00,_
00083       &h00, &h00, &h00, &h00, &h00, &h00), 100
00084 
00085 Function HexToDec(sByte)
00086   For Counter=1 To Len(sByte)
00087     Select Case Mid(sByte,Counter,1)
00088       Case "0"   HexToDec=HexToDec+0*(16^(Len(sByte)-Counter))
00089       Case "1"   HexToDec=HexToDec+1*(16^(Len(sByte)-Counter))
00090       Case "2"   HexToDec=HexToDec+2*(16^(Len(sByte)-Counter))
00091       Case "3"   HexToDec=HexToDec+3*(16^(Len(sByte)-Counter))
00092       Case "4"   HexToDec=HexToDec+4*(16^(Len(sByte)-Counter))
00093       Case "5"   HexToDec=HexToDec+5*(16^(Len(sByte)-Counter))
00094       Case "6"   HexToDec=HexToDec+6*(16^(Len(sByte)-Counter))
00095       Case "7"   HexToDec=HexToDec+7*(16^(Len(sByte)-Counter))
00096       Case "8"   HexToDec=HexToDec+8*(16^(Len(sByte)-Counter))
00097       Case "9"   HexToDec=HexToDec+9*(16^(Len(sByte)-Counter))
00098       Case "A"   HexToDec=HexToDec+10*(16^(Len(sByte)-Counter))
00099       Case "B"   HexToDec=HexToDec+11*(16^(Len(sByte)-Counter))
00100       Case "C"   HexToDec=HexToDec+12*(16^(Len(sByte)-Counter))
00101       Case "D"   HexToDec=HexToDec+13*(16^(Len(sByte)-Counter))
00102       Case "E"   HexToDec=HexToDec+14*(16^(Len(sByte)-Counter))
00103       Case "F"   HexToDec=HexToDec+15*(16^(Len(sByte)-Counter))
00104     End Select
00105   Next
00106 End Function

Copyright © 2000-2007 beeSync. All rights reserved.