ActiveSocket Network Communication Toolkit
Manual Pages
© 1999-2007 - ActiveXperts Software
http://www.activexperts.com
info@activexperts.com
Set objIcmp = CreateObject("ActiveXperts.Icmp") ' Create new Icmp instance
For i = 1 To 4 ' Prepare for 4 consecutive pings
objIcmp.Ping "www.activexperts.com", 2000 ' Ping host (time-out: 2000 msecs)
If( objIcmp.LastError = 0 ) Then
WScript.Echo "Reply from " & strHost & _ ' Display Ping results
": time=" & objIcmp.LastDuration & "ms" & _ ' Display Duration
" TTL=" & objIcmp.LastTtl ' Display TTL
Else
WScript.Echo "Error " & objIcmp.LastError
End If
Next
Set objHttp = CreateObject( "ActiveXperts.Http" ) ' Create new Http instance
objHttp.ProxyServer = "proxy01.intranet.dom" ' Proxy server - if required
objHttp.ProxyAccount = "mjackson" ' Proxy authentication
objHttp.ProxyPassword = "mjackson1" ' Proxy authentication
objHttp.Connect( "www.activexperts.com/products" ) ' Connect to a web server
WScript.Echo "Connect, result: " & objHttp.LastError
If( objHttp.LastError <> 0 ) Then
WScript.Quit
End If
strData = objHttp.ReadData ' Read web page data
WScript.Echo "ReadData, result: " & objHttp.LastError
If( objHttp.LastError <> 0 ) Then
WScript.Echo strData ' Display web page data
End If
objHttp.Disconnect ' Disconnectfrom the web server
Set objFtpServer = CreateObject ( "ActiveXperts.FtpServer" )
objFtpServer.Connect "ftp.activexperts-labs.com","anonymous","" ' Connect to the FTP server
Wscript.Echo "Connect, result: " & objFtpServer.LastError
If( objFtpServer.LastError <> 0 ) Then ' If connect failed then quit
WScript.Quit
End If
objFtpServer.ChangeDir "samples/ASocket/Visual Basic/Telnet" ' Change directory
Wscript.Echo "ChangeDir, result: " & objFtpServer.LastError
If( objFtpServer.LastError <> 0 ) Then ' If ChangeDir fails then disconnect and quit
objFtpServer.Disconnect
WScript.Quit
End If
Set objFtpFile = objFtpServer.FindFirstFile() ' Iterate over all files; start with the first one
While( objFtpServer.LastError = 0 )
WScript.Echo "Name: " & objFtpFile.Name ' Display file name
WScript.Echo "IsDirectory: " & objFtpFile.IsDirectory ' Display directory or file
WScript.Echo "Size: " & objFtpFile.Size ' Display file size
WScript.Echo "Date: " & objFtpFile.Date ' Display file date
' To save the file, call the GetFile function.
' strSaveAs = "C:\temp\" & objFtpFile.Name
' objFtpServer.GetFile objFtpFile.Name, strSaveAs
' Wscript.Echo "Save file, result: " & objFtpServer.LastError
' To delete a file, call the DeleteFile function.
' objFtpServer.DeleteFile objFtpFile.Name
' Wscript.Echo "Delete, result: " & objFtpServer.LastError
Set objFtpFile = objFtpServer.FindNextFile() ' Next file
Wend
objFtpServer.Disconnect ' Disconnect
Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer") ' Create object
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")
objDnsServer.Host = "ns1.interstroom.nl" ' DNS server
objDnsServer.Lookup "activexperts.com", objConstants.asDNS_TYPE_ANY ' Show all DNS records for activexperts.com
WScript.Echo "Lookup, result: " & objDnsServer.LastError
If( objDnsServer.LastError <> 0 ) Then
WScript.Quit
End If
If ( objDnsServer.IsAuthoritative = True ) Then
WScript.Echo "Server is an authority for this domain"
Else
WScript.Echo "Server is not an authority for this domain"
End If
Set objDnsRecord = objDnsServer.GetFirstRecord ' Iterate over all DNS records; get first record
While ( objDnsServer.LastError = 0 )
Select Case objDnsRecord.Type
Case objConstants.asDNS_TYPE_A
WScript.Echo "Type : A"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "IPv4 Address : " & objDnsRecord.Address
Case objConstants.asDNS_TYPE_AAAA
WScript.Echo "Type : AAAA"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "IPv6 Address : " & objDnsRecord.Address
Case objConstants.asDNS_TYPE_CNAME
WScript.Echo "Type : CNAME"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "Alias : " & objDnsRecord.Address
Case objConstants.asDNS_TYPE_MX
WScript.Echo "Type : MX"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "Preference : " & objDnsRecord.Preference
WScript.Echo "Mail Exchange : " & objDnsRecord.MailExchange
Case objConstants.asDNS_TYPE_NS
WScript.Echo "Type : NS"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "Name Server : " & objDnsRecord.NameServer
Case objConstants.asDNS_TYPE_PTR
WScript.Echo "Type : PTR"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "Host : " & objDnsRecord.Address
Case objConstants.asDNS_TYPE_SOA
WScript.Echo "Type : SOA"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "Name Server : " & objDnsRecord.NameServer
WScript.Echo "MailBox : " & objDnsRecord.MailBox
WScript.Echo "Serial : " & objDnsRecord.SerialNumber
WScript.Echo "Refresh : " & objDnsRecord.RefreshInterval
WScript.Echo "Retry Interval : " & objDnsRecord.RetryInterval
WScript.Echo "Expiration Limit : " & objDnsRecord.ExpirationLimit
WScript.Echo "Minimum TTL : " & objDnsRecord.MinimumTTL
End Select
WScript.Echo "TTL : " & objDnsRecord.TTL
WScript.Echo
Set objDnsRecord = objDnsServer.GetNextRecord ' Iterate over all DNS records; get next record
Wend
Set objSsh = CreateObject("ActiveXperts.Ssh") ' Create an Ssh instance
objSsh.Host = "192.168.1.10" ' Hostname or IP address of remote UNIX/LINUX machine
objSsh.UserName = "root" ' Login as 'root'
objSsh.Password = "topsecret" ' Use a password to login
objSsh.Command = "/bin/ls" ' Command to execute
objSsh.ScriptTimeOut = 5000 ' Time-out (in milliseconds)
objSsh.Run ' Execute the command now
WScript.Echo "Run: result = " & objSsh.LastError
If objSsh.LastError <> 0 Then
WScript.Quit
End If
' YES, command has completed
WScript.Echo "StdErr: " & objSsh.StdErr ' Print Standard Output
WScript.Echo "StdOut: " & objSsh.StdOut ' Print Standard Error
WScript.Echo "Ready."
Set objRsh = CreateObject("ActiveXperts.Rsh") ' Create new Rsh instance
objRsh.Clear
objRsh.Host = "192.168.1.10" ' Host/IP of the remote UNIX/LINUX machine
objRsh.Command = "/bin/ls" ' Command to execute on the remote machine
objRsh.ScriptTimeOut = 5000 ' Time-out (in milliseconds)
objRsh.Run ' Run the command now
If objRsh.LastError <> 0 Then
WScript.Echo "Error " & objRsh.LastError
WScript.Quit
End If
' YES, command has completed
WScript.Echo "StdErr: " & objRsh.StdErr ' Display stdout
WScript.Echo "StdOut: " & objRsh.StdOut ' Display stderr
' C L I E N T . V B S
Set objTcp = CreateObject("ActiveXperts.Tcp") ' Create new Tcp instance
Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) ' Create a new Constants instance
objTcp.Protocol= objConstants.asSOCKET_PROTOCOL_RAW ' Plain TCP/IP communications
objTcp.Connect "127.0.0.1", 1500 ' Connect to port 1500 on remote server
WScript.Echo "Connect: result = " & objTcp.LastError
If objTcp.LastError <> 0 Then
WScript.Echo "Error #" & objTcp.LastError & ": " & objTcp.GetErrorDescription( objTcp.LastError )
WScript.Quit
End If
objTcp.SendString "This is a message" ' Send ASCII data
WScript.Echo "SendString, result: " & objTcp.LastError
objTcp.Sleep 1000 ' Hold script for 1000 msec
objTcp.SendString "Quit", False ' Send ASCII data
objTcp.Disconnect ' And finally, disconnect
' S E R V E R . V B S
Set objTcp = CreateObject("ActiveXperts.Tcp") ' Create new Tcp instance
Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) ' Create a new Constants instance
objTcp.Protocol= objConstants.asSOCKET_PROTOCOL_RAW ' Plain TCP/IP communications
objTcp.StartListening 1500 ' Listen on port 1500
If objTcp.LastError <> 0 Then
WScript.Echo "Error " & objTcp.LastError & ": " & objTcp.GetErrorDescription( objTcp.LastError )
WScript.Quit
End If
Do while objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_LISTENING
objTcp.Sleep 1000 ' Wait for incoming connection...
Loop
If objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_LISTENING Then
str = "" ' Connection established
Do While objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_LISTENING and str <> "Quit"
If objTcp.HasData Then
str = objTcp.ReceiveString
WScript.Echo "ReceiveString: " & str
End If
objTcp.Sleep 100
Loop
objTcp.Disconnect ' And finally, disconnect
End If
' C L I E N T . V B S
' Create a socket instance
Set objUdp = CreateObject ( "ActiveXperts.Udp" )
Set objConstants = CreateObject ( "ActiveXperts.ASConstants" )
' Write some information to console
WScript.Echo "ActiveSocket " & objUdp.Version & " demo."
WScript.Echo "Expiration date: " & objUdp.ExpirationDate & vbCrLf
' Open socket to send to port 1500 on remote server
objUdp.Open "localhost", 1500, False
WScript.Echo "Open, result: " & objUdp.LastError & _
" (" & objUdp.GetErrorDescription( objUdp.LastError ) & ")"
If( objUdp.LastError <> 0 ) Then
WScript.Echo "Ready."
WScript.Quit
End If
str = "This is just a message"
objUdp.SendString str ' Send message
WScript.Echo "SendString '" & str & "': result = " & objUdp.LastError
objUdp.Sleep 100
str = "And this is another message"
objUdp.SendString str ' Send another message
WScript.Echo "SendString '" & str & "': result = " & objUdp.LastError
objUdp.Sleep 100
str = "Quit"
objUdp.SendString str ' Send last message
WScript.Echo "SendString '" & str & "': result = " & objUdp.LastError
objUdp.Sleep 100
objUdp.Close ' And finally, close the socket
' S E R V E R . V B S
' Create a socket instance
Set objUdp = CreateObject ( "ActiveXperts.Udp" )
Set objConstants = CreateObject ( "ActiveXperts.ASConstants" )
' Write some information to console
WScript.Echo "ActiveSocket " & objUdp.Version & " demo."
WScript.Echo "Expiration date: " & objUdp.ExpirationDate & vbCrLf
' Open socket to receive UDP datagrams on port 1500 on this machine
objUdp.Open "localhost", 1500, True
WScript.Echo "Open, result: " & objUdp.LastError & _
" (" & objUdp.GetErrorDescription( objUdp.LastError ) & ")"
If( objUdp.LastError <> 0 ) Then
WScript.Echo "Ready."
WScript.Quit
End If
Do While str <> "Quit"
str = objUdp.ReceiveString ' Receive message
If( objUdp.LastError = 0 And str <> "" ) Then
WScript.Echo "ReceiveString: " & str
End If
objUdp.Sleep ( 100 )
Loop
objUdp.Close
Set objNtp = CreateObject("ActiveXperts.Ntp") ' Create new Ntp instance
objNtp.GetTime "fartein.ifi.uio.no" ' Query the time server
If( objNtp.LastError <> 0 ) Then
WScript.Echo "Unable to retrieve time, error: " & objNtp.LastError
WScript.Quit
End If
WScript.Echo "Time on timeserver: " & objNtp.Year & _ ' Display date and time
"/" & objNtp.Month & "/" & objNtp.Day & _ ' Display date and time
" " & objNtp.Hour & ":" & objNtp.Minute & _ ' Display date and time
":" & objNtp.Second
WScript.Echo "DifferenceTime Server / Local PC: " & _ ' Display time offset
objNtp.LocalOffsetSeconds & " seconds" ' Display time offset
End If
Set objSnmpManager = CreateObject( "ActiveXperts.SnmpManager" ) ' Create a new Snmp instance
objSnmpManager.Initialize ' Initialize Snmp
objSnmpManager.Open "192.168.1.100", "public"
If( objSnmpManager.LastError = 0 )
Set objSnmpObject = objSnmpManager.Get( "system.sysName.0" ) ' Get SnmpObject object
While( objSnmpManager.LastError = 0 )
WScript.Echo "Type: " & objSnmpObject.Type
WScript.Echo "Value: " & objSnmpObject.Value
Set objSnmpObject = objSnmpManager.GetNext() ' Get next SnmpObject object
End If
objSnmpManager.Close
End If
objSnmpManager.Shutdown ' Uninitialize Snmp
' T R A P R E C E I V E R . V B S
Set objTrapManager = CreateObject( "ActiveXperts.SnmpTrapManager" ) ' Create a new SnmpTrapManager instance
objTrapManager.Initialize ' Initialize SNMP
If( objTrapManager.LastError <> 0 ) Then
WScript.Quit
End If
objTrapManager.StartListening "public" ' Start listening now
If( objTrapManager.LastError <> 0 ) Then
objTrapManager.Shutdown ' Uninitialize SNMP
WScript.Quit
End If
Set objSnmpTrap = objTrapManager.GetFirstTrap ' Get trap
While( objTrapManager.LastError = 0 )
WScript.Echo "Trap from : " & objSnmpTrap.Host
WScript.Echo " Community : " & objSnmpTrap.Community
Set objSnmpObject = objSnmpTrap.GetFirstObject
While( objSnmpTrap.LastError = 0 ) ' iterate over all variables in the trap
WScript.Echo "OID : " & objSnmpObject.OID
WScript.Echo "Value:" & objSnmpObject.Value
WScript.Echo "Type:" & GetTypeString( objSnmpObject.Type )
Set objSnmpObject = objSnmpTrap.GetNextObject
WEnd
Set objSnmpTrap = objTrapManager.GetNextTrap ' Get next trap
WEnd
objTrapManager.StopListening ' Stop listening for incoming traps
objTrapManager.Shutdown ' Uninitialize SNMP
' T R A P S E N D E R . V B S
Set objSnmpTrapManager = CreateObject("ActiveXperts.SnmpTrapManager") ' Create a new SnmpTrapManager instance
Set objSnmpTrap = CreateObject( "ActiveXperts.SnmpTrap" ) ' Create a new SnmpTrap instance
Set objSnmpObject = CreateObject( "ActiveXperts.SnmpObject" ) ' Create a new SnmpObject instance
Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) ' Create a new Constants instance
objSnmpTrapManager.Initialize ' Initialize SNMP
If( objSnmpTrapManager.LastError <> 0 ) Then
WScript.Quit
End If
' Set trap properties
objSnmpTrap.Clear()
objSnmpTrap.Host = "server06"
objSnmpTrap.Community = "public"
' Add a variable to the trap
objSnmpObject.Clear() ' Clear trap object
objSnmpObject.OID = ".1.3.6.1.2.1.1.5.0" ' Set trap properties
objSnmpObject.Type = objConstants.asSNMP_TYPE_IPADDRESS ' Set trap properties
objSnmpObject.Value = "10.0.0.1" ' Set trap properties
objSnmpTrap.AddObject objSnmpObject ' Add the trap to the queue
' Add another variable to the trap
objSnmpObject.Clear() ' Clear trap object
objSnmpObject.OID = ".1.3.6.1.2.1.1.5.1" ' Set trap properties
objSnmpObject.Type = objConstants.asSNMP_TYPE_OCTETSTRING ' Set trap properties
objSnmpObject.Value = "One two three" ' Set trap properties
objSnmpTrap.AddObject objSnmpObject ' Add the trap to the queue
objSnmpTrapManager.Send objSnmpTrap ' Send trap
WScript.Echo "Send, result: " & objSnmpTrapManager.LastError ' Display the result
objSnmpTrapManager.Shutdown ' Uninitialize SNMP
Set objTcp = CreateObject("ActiveXperts.Tcp") ' Create new Tcp instance
Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) ' Create a new Constants instance
objTcp.Protocol= objConstants.asSOCKET_PROTOCOL_TELNET ' Telnet communications
objTcp.Connect "www.activexperts.com", 80 ' Connect to web site on port 80
Wscript.Echo "Connect,, result: " & objTcp.LastError
If objTcp.LastError <> 0 Then
WScript.Quit
End If
If objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_CONNECTED Then
strReceived = "" ' Connection established
objTcp.Sleep 1000
objTcp.SendString "GET /activsocket/demopage/ HTTP/1.1" ' Send string
objTcp.SendString "Host: www.activexperts.com" & vbCrlf ' Send string
objTcp.Sleep 1000
If objTcp.HasData Then
strReceived = objTcp.ReceiveString ' Receive data
WScript.Echo "RECV: " & strReceived
End If
objTcp.Sleep 1000
objTcp.Disconnect ' Disconnect from server
End If
Set objIPC = CreateObject( "ActiveXperts.IPtoCountry" ) ' Create a new IPtoCountry instance
objIPC.Host = "www.activexperts.com" ' Host name (or IP address) that you want to resolve
objIPC.Query() ' Host name (or IP address) that you want to resolve
WScript.Echo "Query, result: " & objIPC.LastError ' Result of Query; 0 means: success
If objIPC.LastError = 0 Then
WScript.Echo "Host " & strHost & " is located in " & objIPC.CountryName
End If
Set objWOL = CreateObject( "ActiveXperts.WOL" ) ' Create a new WOL instance strMAC = "00-10-4B-BA-7A-51" objWOL.WakeUp strMAC ' Send magic packet to remote station identified by MAC WScript.Echo "WakeUp, result = " & objWOL.LastError ' Display the result
Imports ASOCKETLib
and declare and create an object like this:
Dim objTcp As Tcp ' Declaration
objTcp = New Tcp() ' Creation
You can use different ActiveSocket objects in one Visual Basic .NET application. The following code shows how to declare and create all ActiveSocket objects:
Dim objConstants As SocketConstants ' Declaration objConstants = New SocketConstants() ' Creation Dim objIcmp As Icmp ' Declaration objIcmp = New Icmp() ' Creation Dim objTcp As Tcp ' Declaration objTcp = New Tcp() ' Creation Dim objUdp As Udp ' Declaration objUdp = New Udp() ' Creation Dim objHttp As Http ' Declaration objHttp = New Http() ' Creation Dim objFtpServer As FtpServer ' Declaration objFtpServer = New FtpServer() ' Creation Dim objFtpFile As FtpFile ' Declaration objFtpFile = New FtpFile() ' Creation Dim objDnsServer As DnsServer ' Declaration objDnsServer = New DnsServer() ' Creation Dim objDnsRecord As DnsRecord ' Declaration objDnsRecord = New DnsRecord() ' Creation Dim objNtp As Ntp ' Declaration objNtp = New Ntp() ' Creation Dim objSsh As Ssh ' Declaration objSsh = New Ssh() ' Creation Dim objRsh As Rsh ' Declaration objRsh = New Rsh() ' Creation Dim objSnmpManager As SnmpManager ' Declaration objSnmpManager = New SnmpManager() ' Creation Dim objSnmpObject As SnmpObject ' Declaration objSnmpObject = New SnmpObject() ' Creation Dim objSnmpTrapManager As SnmpTrapManager ' Declaration objSnmpTrapManager = New SnmpTrapManager() ' Creation Dim objSnmpTrap As SnmpTrap ' Declaration objSnmpTrap = New SnmpTrap() ' Creation Dim objSnmpMib As SnmpMibBrowser ' Declaration objSnmpMib = New SnmpMibBrowser() ' Creation Dim objIPC As IPtoCountry ' Declaration objIPC = New IPtoCountry() ' Creation Dim objWOL As WOL ' Declaration objWOL = New WOL() ' CreationAfter these declarations and creation of the object(s), you can use the objects inside your Visual Basic .NET project.
using ASOCKETLib;
and declare and create an object like this:
Tcp objTcp; // Declaration
objTcp = new Tcp(); // Creation
You can use different ActiveSocket objects in one Visual C# .NET application. The following code shows how to declare and create all ActiveSocket objects:
SocketConstants objConstants; // Declaration objConstants = new SocketConstants(); // Creation Tcp objTcp; // Declaration objTcp = new Tcp(); // Creation Udp objUdp; // Declaration objUdp = new Udp(); // Creation Icmp objIcmp; // Declaration objIcmp = new Icmp(); // Creation Http objHttp; // Declaration objHttp = new Http(); // Creation FtpServer objFtpServer; // Declaration objFtpServer = new FtpServer(); // Creation FtpFile objFtpFile; // Declaration objFtpFile = new FtpFile(); // Creation DnsServer objDnsServer; // Declaration objDnsServer = new DnsServer(); // Creation DnsRecord objDnsRecord; // Declaration objDnsRecord = new DnsRecord(); // Creation Ntp objNtp; // Declaration objNtp = new Ntp(); // Creation Ssh objSsh // Declaration objSsh = new Ssh(); // Creation Rsh objRsh // Declaration objRsh = new Rsh(); // Creation SnmpManager objSnmpManager; // Declaration objSnmpManager = new SnmpManager(); // Creation SnmpObject objSnmObject; // Declaration objSnmpObject = new SnmpObject(); // Creation SnmpTrapManager objSnmpTrapManager; // Declaration objSnmpTrapManager = new SnmpTrapManager(); // Creation SnmpTrap objSnmpTrap; // Declaration objSnmpTrap = new SnmpTrap(); // Creation SnmpMibBrowser objSnmpMib; // Declaration objSnmpMib = new SnmpMibBrowser(); // Creation IPtoCountry objIPC; // Declaration objIPC = new IPtoCountry(); // Creation WOL objWOL; // Declaration objWOL = new WOL(); // CreationAfter these declarations and creation of the object(s), you can use the objects inside your Visual C# .NET code.
Dim objConstants As ASOCKETLib.SocketConstants ' Declaration Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) ' Creation Dim objIcmp As ASOCKETLib.Icmp ' Declaration Set objIcmp = CreateObject( "ActiveXperts.Icmp" ) ' Creation Dim objTcp As ASOCKETLib.Tcp ' Declaration Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Creation Dim objUdp As ASOCKETLib.Udp ' Declaration Set objUdp = CreateObject( "ActiveXperts.Udp" ) ' Creation Dim objHttp As ASOCKETLib.Http ' Declaration Set objHttp = CreateObject( "ActiveXperts.Http" ) ' Creation Dim objFtpServer As ASOCKETLib.FtpServer ' Declaration Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" ) ' Creation Dim objFtpFile As ASOCKETLib.FtpFile ' Declaration Set objFtpFile = CreateObject( "ActiveXperts.FtpFile") ' Creation Dim objDnsServer As ASOCKETLib.DnsServer ' Declaration Set objDnsServer = CreateObject( "ActiveXperts.DnsServer" ) ' Creation Dim objDnsRecord As ASOCKETLib.DnsRecord ' Declaration Set objDnsRecord = CreateObject( "ActiveXperts.DnsRecord") ' Creation Dim objNtp As ASOCKETLib.Ntp ' Declaration Set objNtp = CreateObject( "ActiveXperts.Ntp" ) ' Creation Dim objSsh As ASOCKETLib.Ssh ' Declaration Set objSsh = CreateObject( "ActiveXperts.Ssh" ) ' Creation Dim objRsh As ASOCKETLib.Rsh ' Declaration Set objRsh = CreateObject( "ActiveXperts.Rsh" ) ' Creation Dim objSnmpManager As ASOCKETLib.SnmpManager ' Declaration Set objSnmpManager = CreateObject( "ActiveXperts.SnmpManager" ) ' Creation Dim objSnmpObject As ASOCKETLib.SnmpObject ' Declaration Set objSnmpObject = CreateObject( "ActiveXperts.SnmpObject") ' Creation Dim objSnmpTrapManager As ASOCKETLib.SnmpTrapManager ' Declaration Set objSnmpTrapManager = CreateObject( "ActiveXperts.SnmpTrapManager" ) ' Creation Dim objSnmpTrap As ASOCKETLib.SnmpTrap ' Declaration Set objSnmpTrap = CreateObject( "ActiveXperts.SnmpTrap" ) ' Creation Dim objSnmpMib As ASOCKETLib.SnmpMibBrowser ' Declaration Set objSnmpMib = CreateObject( "ActiveXperts.SnmpMibBrowser" ) ' Creation Dim objIPC As ASOCKETLib.IPtoCountry ' Declaration Set objIPC = CreateObject( "ActiveXperts.IPtoCountry") ' Creation Dim objWOL As ASOCKETLib.WOL ' Declaration Set objWOL = CreateObject( "ActiveXperts.WOL") ' CreationVisual Basic samples are installed during installation of the product. They can also be found on our website.
ISocketConstants *pConstants; // Declaration
CoCreateInstance(CLSID_SocketConstants, NULL, CLSCTX_INPROC_SERVER, IID_ISocketConstants, (void**) &pConstants ); // Creation
IIcmp *pIcmp; // Declaration
CoCreateInstance(CLSID_Icmp, NULL, CLSCTX_INPROC_SERVER, IID_IIcmp, (void**) &pIcmp ); // Creation
ITcp *pTcp; // Declaration
CoCreateInstance(CLSID_Tcp, NULL, CLSCTX_INPROC_SERVER, IID_ITcp, (void**) &pTcp ); // Creation
IUdp *pUdp; // Declaration
CoCreateInstance(CLSID_Udp, NULL, CLSCTX_INPROC_SERVER, IID_IUdp, (void**) &pUdp ); // Creation
IHttp *pHttp; // Declaration
CoCreateInstance(CLSID_Http, NULL, CLSCTX_INPROC_SERVER, IID_IHttp, (void**) &pHttp ); // Creation
IFtpServer *pFtpServer; // Declaration
CoCreateInstance(CLSID_FtpServer, NULL, CLSCTX_INPROC_SERVER, IID_IFtpServer, (void**) &pFtpServer ) // Creation
IFtpFile *pFtpFile; // Declaration
CoCreateInstance(CLSID_FtpFile, NULL, CLSCTX_INPROC_SERVER, IID_IFtpFile, (void**) &pFtpFile ) // Creation
IDnsServer *pDnsServer; // Declaration
CoCreateInstance(CLSID_DnsServer, NULL, CLSCTX_INPROC_SERVER, IID_IDnsServer, (void**) &pDnsServer ) // Creation
IDnsRecord *pDnsRecord; // Declaration
CoCreateInstance(CLSID_DnsRecord, NULL, CLSCTX_INPROC_SERVER, IID_IDnsRecord, (void**) &pDnsRecord ) // Creation
INtp *pNtp; // Declaration
CoCreateInstance(CLSID_Ntp, NULL, CLSCTX_INPROC_SERVER, IID_INtp, (void**) &pNtp ) // Creation
ISsh *pSsh; // Declaration
CoCreateInstance(CLSID_Ssh, NULL, CLSCTX_INPROC_SERVER, IID_ISsh, (void**) &pSsh ) // Creation
IRSh *pRsh; // Declaration
CoCreateInstance(CLSID_RSh, NULL, CLSCTX_INPROC_SERVER, IID_IRSh, (void**) &pRSh ) // Creation
ISnmpManager *pSnmpManager; // Declaration
CoCreateInstance(CLSID_SnmpManager, NULL, CLSCTX_INPROC_SERVER, IID_ISnmpManager, (void**) &pSnmpManager ) // Creation
ISnmpObject *pSnmpObject; // Declaration
CoCreateInstance(CLSID_SnmpObject, NULL, CLSCTX_INPROC_SERVER, IID_ISnmpObject, (void**) &pSnmpObject ) // Creation
ISnmpTrapManager *pSnmpTrapManager; // Declaration
CoCreateInstance(CLSID_SnmpTrapManager, NULL, CLSCTX_INPROC_SERVER, IID_ISnmpTrapManager, (void**) &pSnmpTrapManager )// Creation
ISnmpTrap *pSnmpTrap; // Declaration
CoCreateInstance(CLSID_SnmpTrap, NULL, CLSCTX_INPROC_SERVER, IID_ISnmpTrap, (void**) &pSnmpTrap ) // Creation
ISnmpMibBrowser *pSnmpMib; // Declaration
CoCreateInstance(CLSID_SnmpMibBrowser, NULL, CLSCTX_INPROC_SERVER, IID_ISnmpMibBrowser, (void**) &pSnmpMib ) // Creation
IIPtoCountry *pIPC; // Declaration
CoCreateInstance(CLSID_IPtoCountry, NULL, CLSCTX_INPROC_SERVER, IID_IIPtoCountry, (void**) &pIPC ) // Creation
IWOL *pWol; // Declaration
CoCreateInstance(CLSID_WOL, NULL, CLSCTX_INPROC_SERVER, IID_IWOL, (void**) &pWOL ) // Creation
Visual C++ samples are installed as part of the product, but can also be found on our website.
<html>
<body>
Version:
<script language=vbscript runat=server>
Set objTcp = CreateObject( "ActiveXperts.Tcp" )
Response.Write objTcp.Version
</script>
</body>
</html>
objConst : ISocketConstants; { Declaration of the interface class }
objConst := TSocketConstants.Create(Form1).DefaultInterface; { Creation new instance of the object }
objTcp : ITcp; { Declaration of the interface class }
objTcp := TTcp.Create(Form1).DefaultInterface; { Creation new instance of the object }
objUdp : IUdp; { Declaration of the interface class }
objUdp := TUdp.Create(Form1).DefaultInterface; { Creation new instance of the object }
objIcmp : IICmp; { Declaration of the interface class }
objIcmp := TIcmp.Create(Form1).DefaultInterface; { Creation new instance of the object }
objHttp : IHttp; { Declaration of the interface class }
objHttp := THttp.Create(Form1).DefaultInterface; { Creation new instance of the object }
objFtpServer : IFtpServer; { Declaration of the interface class }
objFtpServer := TFtpServer.Create(Form1).DefaultInterface; { Creation new instance of the object }
objFtpFile : IFtpFile; { Declaration of the interface class }
objFtpFile := TFtpFile.Create(Form1).DefaultInterface; { Creation new instance of the object }
objDnsServer : IDnsServer; { Declaration of the interface class }
objDnsServer := TDnsServer.Create(Form1).DefaultInterface; { Creation new instance of the object }
objDnsRecord : IDnsRecord; { Declaration of the interface class }
objDnsRecord := TDnsRecord.Create(Form1).DefaultInterface; { Creation new instance of the object }
objNtp : INtp; { Declaration of the interface class }
objNtp := TNtp.Create(Form1).DefaultInterface; { Creation new instance of the object }
objSsh : ISsh; { Declaration of the interface class }
objSsh := TSsh.Create(Form1).DefaultInterface; { Creation new instance of the object }
objRsh : IRSh; { Declaration of the interface class }
objRsh := TRSh.Create(Form1).DefaultInterface; { Creation new instance of the object }
objManager : ISnmpManager; { Declaration of the interface class }
objManager := TSnmpManager.Create(Form1).DefaultInterface; { Creation new instance of the object }
objSnmpObject : ISnmpObject; { Declaration of the interface class }
objSnmpObject := TSnmpObject.Create(Form1).DefaultInterface; { Creation new instance of the object }
objManager : ISnmpTrapManager; { Declaration of the interface class }
objManager := TSnmpTrapManager.Create(Form1).DefaultInterface; { Creation new instance of the object }
objData : ISnmpTrapData; { Declaration of the interface class }
objData := TSnmpTrapData.Create(Form1).DefaultInterface; { Creation new instance of the object }
objSnmpMib : ISnmpMibBrowser; { Declaration of the interface class }
objSnmpMib := TSnmpMibBrowser.Create(Form1).DefaultInterface; { Creation new instance of the object }
objIPC : IIPtoCountry; { Declaration of the interface class }
objIPC := TIPtoCountry.Create(Form1).DefaultInterface; { Creation new instance of the object }
objWOL : IWOL; { Declaration of the interface class }
objWOL := TWOL.Create(Form1).DefaultInterface; { Creation new instance of the object }
After these declarations and creation of the object(s), you can use the
objects in your Delphi projects.Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) WScript.Echo objConstants.asSOCKET_PROTOCOL_RAW WScript.Echo objConstants.asSOCKET_PROTOCOL_TELNET ... WScript.Echo objConstants.asSNMP_TYPE_INTEGER WScript.Echo objConstants.asSNMP_TYPE_IPADDRESS ...
|
|
|
|
|
|
|
|
Set objIcmp = CreateObject("ActiveXperts.Icmp") ' Create Icmp object
objIcmp.Ping "www.activexperts.com", 2000 ' Ping host; timeout 2000 ms
If( objIcmp.LastError = 0 ) Then
WScript.Echo "Success, duration: " & objIcmp.LastDuration & "ms"
Else
WScript.Echo "Error " & objIcmp.LastError & ": " & objIcmp.GetErrorDescription( objIcmp.LastError )
End If
WScript.Echo "Ready."
|
|
Set objIcmp = CreateObject( "ActiveXperts.Icmp" ) ' Create Icmp object
WScript.Echo "Version: " & objIcmp.Version
Set objIcmp = CreateObject( "ActiveXperts.Icmp" ) ' Create Icmp object
WScript.Echo "ExpirationDate: " & objIcmp.ExpirationDate
Set objIcmp = CreateObject( "ActiveXperts.Icmp" )
objIcmp.Ttl = 100 ' Use a different Time To Live than the default 255 value
objIcmp.Ping "www.monitortools.com", 2000 ' Ping monitortools.com, timeout after 2000 msec
If( objIcmp.LastError = 0 ) Then
WScript.Echo "TTL: " & objIcmp.LastTtl
End If
Set objIcmp = CreateObject( "ActiveXperts.Icmp" ) ' Create Icmp object
objIcmp.BufferSize = 64 ' Use a different buffer size than the default (32 bytes)
objIcmp.Ping "www.monitortools.com", 2000 ' Ping monitortools.com, timeout after 2000 msec
Set objIcmp = CreateObject( "ActiveXperts.Icmp" ) ' Create Icmp object
objIcmp.Ping "server.mydomain.com", 2000
WScript.Echo "LastError: " & objIcmp.LastError
Set objIcmp = CreateObject( "ActiveXperts.Icmp" ) ' Create Icmp object
objIcmp.Ping "www.activexperts.com", 2000
WScript.Echo "Duration of ICMP/Ping operation: " & objIcmp.LastDuration
Set objIcmp = CreateObject( "ActiveXperts.Icmp" ) ' Create Icmp object
objIcmp.Ping "www.monitortools.com", 2000
If( objIcmp.LastError = 0 ) Then
WScript.Echo "TTL: " & objIcmp.LastTtl
End If
Set objIcmp = CreateObject( "ActiveXperts.Icmp" ) ' Create Icmp object
objIcmp.Ping "192.168.1.1", 2000
objIcmp.Clear
objIcmp.Ping "192.168.1.2", 2000
Set objIcmp = CreateObject( "ActiveXperts.Icmp" ) ' Create Icmp object
objIcmp.Ping "192.168.1.1", 2000
objIcmp.Clear
objIcmp.Ping "192.168.1.2", 2000
Set objIcmp = CreateObject( "ActiveXperts.Icmp" ) ' Create Icmp object
objIcmp.Ping "www.thisdoesnotexist.com", 2000
WScript.Echo "LastError: " & objIcmp.LastError
WScript.Echo "Error description: " & objIcmp.GetErrorDescription( objIcmp.LastError )
Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Create Tcp object
Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
objTcp.StartListening 1500 ' listen on port 1500 for incoming connection
Then, the server must wait until a connection is established, i.e. when the state of the connection changes from asSOCKET_CONNSTATE_LISTENING to asSOCKET_CONNSTATE_CONNECTED: Do While objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_LISTENING
' Just do nothing
Loop
If objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_CONNECTED Then
' YES, connection established.
End If
Once the connection has been established, server and client can communicate with eachother. They can both send and receive. To receive information, use the ReceiveString function:
Do While objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_CONNECTED
str = objTcp.ReceiveString
Loop
Each time you call a function, you can check the result by checking the LastError property. For instance: Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Create Tcp object
Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
objTcp.StartListening 1500 ' listen on port 1500 for incoming connection
If objTcp.LastError = 0 Then
' Yes, socket is listening on the specific port for an incoming connection
End If
On the client side, the client must connect to a server on a specific server-port: Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Create Tcp object
Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
objTcp.Connect "remoteserver", 1500 ' connect on port 1500
If objTcp.LastError = 0 Then
' YES, connection established
End If
Now, client and server are peers. They can both send and receive. They can send in the following way:
objTcp.SendData "This is a message from client.vbs." ' Send data
A process can disconnect the session anytime they want:
objTcp.Disconnect ' Disconnect
Set objTcp = CreateObject("ActiveXperts.Tcp") ' Create Tcp object
Set objConstants= CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
objTcp.Protocol = objConstants.asSOCKET_PROTOCOL_TELNET ' Telnet protocol
objTcp.Connect "www.activexperts.com", 80 ' Connect on port 80 to remote server
WScript.Echo "Connect, result: " & objTcp.LastError
If objTcp.LastError <> 0 Then
WScript.Quit
If objTcp.ConnectionState = asSOCKET_CONNSTATE_CONNECTED Then.
WScript.Echo "Connection established" & vbCrLf
strReceived = ""
nCounter = nCounter + 1
objTcp.Sleep 1000
objTcp.SendString "GET /activsocket/demopage/ HTTP/1.1" ' Send data
objTcp.SendString "Host: www.activexperts.com" ' Send data
objTcp.SendString "" ' Send data (only CRLF)
objTcp.Sleep 1000
If objTcp.HasData Then
strReceived = objTcp.ReceiveString ' Receive data
WScript.Echo "RECV: " & strReceived
End If
objTcp.Sleep 1000
objTcp.Disconnect ' Disconnect
End If
|
|
Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Create Tcp object
Response.Write "Version: " & objTcp.Version
Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Create Tcp object
Response.Write "ExpirationDate: " & objTcp.ExpirationDate
Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Create Tcp object
Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
objTcp.Protocol = objConstants.asSOCKET_PROTOCOL_TELNET ' Use telnet protocol
objTcp.Connect "server.mydomain.com", 23
Response.Write "Connect, result: " & objTcp.LastError
Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Create Tcp object
...
objTcp.Connect "192.168.1.1", 8081 ' Connect
If objTcp.LastError = 0 Then
objTcp.NewLine = vbCr ' Use CR in the subsequent ReceiveString/SendString calls ' transmitted by the WriteString function
objTcp.SendString "Hello"
If objTcp.LastError = 0 Then
WScript.Echo "SendString was successful"
Else
WScript.Echo "SendString failed"
End If
objTcp.Disconnect
End If
Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Create Tcp object
Set objConstants = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
...
objTcp.StartListening 8081 ' Create Tcp object
If objTcp.LastError <> 0 Then
WScript.Quit
End If
...
Do While objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_LISTENING
objTcp.Sleep 1000
Loop
If objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_CONNECTED Then
' YES, connection established.
End If
Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Create Tcp object
...
objTcp.Connect "192.168.1.1", 8081 ' Connect to 192.168.1.1 on port 8081
WScript.Echo "Connect, result: " & objTcp.LastError ' Print the result
If( objTcp.LastError = 0 And objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_CONNECTED ) Then
WScript.Echo "Connecteed to remote party: " & objTcp.RemoteAddress ' IP:Port of the remote party
End If
Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Create Tcp object
objTcp.Connect "server.mydomain.com", 8081
Response.Write "Connect, result: " & objTcp.LastError
Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Create Tcp object
...
objTcp.Connect "192.168.1.1", 8081 ' Connect to 192.168.1.1 on port 8081
WScript.Echo "Connect, result: " & objTcp.LastError ' Print the result
objTcp.Connect "myserver", 8081
Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Create Tcp object
...
objTcp.Connect "192.168.1.1", 8081 ' Connect
If objTcp.LastError = 0 Then
objTcp.SendData "Hello"
objTcp.Disconnect ' Disconnect
End If
Set objTcp = CreateObject( "ActiveXperts.Tcp" ) ' Create Tcp object
...
objTcp.Connect "192.168.1.1", 8081 ' Connect
If objTcp.LastError = 0 Then
objTcp.SendString "Hello"
If