VBScript/JScript Networking: Connect either UDP or TCP

前端 未结 1 1334
我寻月下人不归
我寻月下人不归 2021-01-13 02:56

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 loc

相关标签:
1条回答
  • 2021-01-13 03:46

    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.

    0 讨论(0)
提交回复
热议问题