The following code snippets (VBScript) illustrate how to use various SMS and Pager Toolkit objects.
ICMP sample (ping a remote host)
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
HTTP sample (read a web page)
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
FTP sample (list files in a specific directory on an FTP 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
TFTP sample (download a file from a remote TFTP host, save it locally)
Set objTftpServer = CreateObject ( "ActiveXperts.TftpServer" )
objTftp.Get "10.1.1.10", "/folder1/file.txt", "c:\\file.txt" ' Download file, save it locally
Wscript.Echo "Get, result: " & objTftp.LastError
If( objTftp.LastError <> 0 ) Then ' If download failed then quit
WScript.Quit
End If
WScript.Echo "Packets received: " & objTftp.PacketsReceived ' Print download statistics
WScript.Echo "Bytes received: " & objTftp.BytesReceived ' Print download statistics
DNS sample (list all records for a specific domain)
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
SSH sample (run a command on a remote LINUX/UNIX host in a secure way)
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."
RSH sample (run a command on a remote LINUX/UNIX host in an unsecure way)
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
Client/Server TCP application (1 client script, 1 server script)
' 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
Client/Server UDP application (1 client script, 1 server script)
' 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
NTP sample (query a remote time server)
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
SNMP Walker (walk through the SNMP MIB database)
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
SNMP Traps (1 sender script, 1 receiver script)
' 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
Telnet sample (connect to a web site through a telnet session)
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
IP to Country sample (maps an IP address to a country
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
Wake_On-LAN sample (Power-Up a remote computer)
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
First, make sure the ActiveSocket component (ASocket.dll) is registered on the machine. In case you didn't use the installation program,
be sure you used the REGSVR32.EXE program to register to component.
Then, add a reference to the ActiveSocket component using the Visual Basic .NET Solution Explorer:
- Start the Solution Provider, go to the project's 'References' container;
- Choose 'Add Reference' from the context menu;
- From the COM components tab, choose the ActiveSocket component.
On top of the code, make this declaration:
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 objTftpServer As TftpServer ' Declaration
objTftpServer = New TftpServer() ' 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() ' Creation
After these declarations and creation of the object(s), you can use the objects inside your Visual Basic .NET project.
First, make sure the ActiveSocket component (ASocket.dll) is registered on the machine. In case you didn't use the installation program,
be sure you used the REGSVR32.EXE program to register to component.
Then, add a reference to the object using the Visual C# Solution Explorer:
- Start the Solution Provider, go to the project's 'References' container;
- Choose 'Add Reference' from the context menu;
- From the COM components tab, choose the ActiveSocket component.
On top of your code, make this declaration:
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
TftpServer objTftpServer; // Declaration
objTftpServer = new TftpServer(); // 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(); // Creation
After these declarations and creation of the object(s), you can use the objects inside your Visual C# .NET code.
ActiveSocket can be used in Visual Basic 5.x or higher. In Visual Basic, go to the 'Project/References...' menu item and check the box next to ActiveSocket Type Library. Now, you can declare and create ActiveSocket objects.
Create a new ActiveSocket object using the 'CreateObject' function:
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 objTftpServer As ASOCKETLib.TftpServer ' Declaration
Set objTftpServer = CreateObject( "ActiveXperts.TftpServer" ) ' 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") ' Creation
Visual Basic samples are installed during installation of the product. They can also be found on our
website.
ActiveSocket can be used in Visual C++ projects. Include the *.h and *.c file provided by ActiveXperts to bind your code to the ActiveSocket component.
These files are located in the
Include directory of the Visual C++ samples directory. These are the files:
- ASocket.h
- ASocket_i.c
- ASocketConstants.h
Create the various ActiveSocket object instances like this:
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
ITftpServer *pTftpServer; // Declaration
CoCreateInstance(CLSID_TftpServer, NULL, CLSCTX_INPROC_SERVER, IID_ITftpServer, (void**) &pTftpServer ) // 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>
Make sure the ActiveSocket Toolkit is installed on your system.
For details about installation,
click here.
First, add a reference to the ActiveSocket objects:
-
Go to Project->Import Type Library;
-
Select 'ActiveSocket 3.x Type Library';
-
Click 'Install';
-
The project 'dclusr.dpk' will be opened. Click 'Yes';
-
You can now use the ActiveSocket toolkit within your application by selecting the component from the 'ActiveX' component bar.
Create the various ActiveSocket object instances like this:
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 }
objTftpServer : ITftpServer; { Declaration of the interface class }
objTftpServer := TFtpServer.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.