Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBScript/JScript Networking: Connect either UDP or TCP

Tags:

udp

vbscript

How can I use a stand-alone VBScript or JScript file to connect to a port on localhost, either UDP or TCP (preferable UDP)? I need to send a command to a certain port on localhost. The command is small and there will not be any packet loss to localhost (even if there was, it would not be that bad), that is why UDP would work great, just send a packet.

But at the moment I am having a hard time finding any examples on VBScript or JScript networking.

I don't care about anything before Windows XP.

like image 909
700 Software Avatar asked Jun 14 '11 19:06

700 Software


1 Answers

VBScript and JScript do not natively have the ability to directly use Sockets. What these languages do allow you to do is to interact with ActiveX/COM objects that have the ability to use Sockets.

For example, you can use MSXML2.XMLHTTP to talk to an HTTP/HTTPS server.

Dim objHTTP
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
objHTTP.open "GET", "http://www.google.com", false
objHTTP.send 
WScript.Echo objHTTP.responseText

Now, the real question. Does Windows have an ActiveX/COM object for interacting with raw Sockets? The short answer here is No, but you do have alternatives.

  • There is a "Winsock ActiveX" library named mswinsck.ocx that comes with very old versions of Visual Studio (version 6 and earlier). Although, getting this library to work will be kind of tricky as it was meant to be used from Visual Basic and not VBScript.

  • You can purchase one from a 3rd party

  • You can write your own. This may be more trouble than it is worth, though. You'll be stepping so far outside of VBScript that it would be simpler to give up on VBScript and write a proper program for doing this.

  • You can switch to a more verbose language such as ActiveState Perl or Python. Both have native support for sockets, but again, this might be outside of your comfort zone.

like image 99
jveazey Avatar answered Sep 30 '22 07:09

jveazey