B
Ben
I am sending a packet to a server when an event is triggered. When the
event is triggered (only once) I get two packets sent. I am supposed to only
get one packet. I used the MS SDK as the basis for this program. What am I
doing wrong?
Thanks,
Ben
Namespace Microsoft.Samples
Module LogMonitor
Dim WithEvents evtSec As New EventLog("Security")
Public Sub Main()
evtSec.MachineName = "."
AddHandler evtSec.EntryWritten, AddressOf OnEntryWritten
evtSec.EnableRaisingEvents = True
While (Console.Read() <> 113)
System.Threading.Thread.Sleep(500)
End While
End Sub
Sub OnEntryWritten(ByVal source As Object, ByVal e As
EntryWrittenEventArgs) Handles evtApp.EntryWritten, evtSec.EntryWritten,
evtSys.EntryWritten
Try
sendinfo(e, "192.168.1.33", "44000")
Catch se As Exception
MsgBox(se.ToString(), , "LogMonitor Error")
End Try
End Sub
Sub sendinfo(ByVal e As EntryWrittenEventArgs, ByVal servername As
String, ByVal portnum As String)
Dim sendbuffer As [Byte]()
Dim sendstring As String
Dim hostname As String = System.Net.Dns.GetHostName()
Dim tcpClient As New System.Net.Sockets.TcpClient()
tcpClient.Connect(servername, portnum)
Dim networkStream As System.Net.Sockets.NetworkStream =
tcpClient.GetStream()
sendstring = "Check my security log"
sendbuffer = System.Text.Encoding.ASCII.GetBytes(sendstring)
networkStream.Write(sendbuffer, 0, sendbuffer.Length)
tcpClient.Close()
End Sub
End Module
End Namespace
event is triggered (only once) I get two packets sent. I am supposed to only
get one packet. I used the MS SDK as the basis for this program. What am I
doing wrong?
Thanks,
Ben
Namespace Microsoft.Samples
Module LogMonitor
Dim WithEvents evtSec As New EventLog("Security")
Public Sub Main()
evtSec.MachineName = "."
AddHandler evtSec.EntryWritten, AddressOf OnEntryWritten
evtSec.EnableRaisingEvents = True
While (Console.Read() <> 113)
System.Threading.Thread.Sleep(500)
End While
End Sub
Sub OnEntryWritten(ByVal source As Object, ByVal e As
EntryWrittenEventArgs) Handles evtApp.EntryWritten, evtSec.EntryWritten,
evtSys.EntryWritten
Try
sendinfo(e, "192.168.1.33", "44000")
Catch se As Exception
MsgBox(se.ToString(), , "LogMonitor Error")
End Try
End Sub
Sub sendinfo(ByVal e As EntryWrittenEventArgs, ByVal servername As
String, ByVal portnum As String)
Dim sendbuffer As [Byte]()
Dim sendstring As String
Dim hostname As String = System.Net.Dns.GetHostName()
Dim tcpClient As New System.Net.Sockets.TcpClient()
tcpClient.Connect(servername, portnum)
Dim networkStream As System.Net.Sockets.NetworkStream =
tcpClient.GetStream()
sendstring = "Check my security log"
sendbuffer = System.Text.Encoding.ASCII.GetBytes(sendstring)
networkStream.Write(sendbuffer, 0, sendbuffer.Length)
tcpClient.Close()
End Sub
End Module
End Namespace