Hi guys,
I'm writing a simple application which pings a range of IP addresses from a database, and simply records the result back into a table.
I initially wrote it as a console app and everything worked fine. Now that I've converted the code to run as a service it throws a socket error:
In the above example the input to the ping function was an IP address.
I'm confused, because it looks like it's failing a DNS lookup, but I'm passing it an IP address, not a host name. Is this some security setting that's different because the app runs as a service? Its running as my network account which has admin rights.
Here is the sub which performs the ping...
Any help would be appreciated as this is starting to get frustrating!
Thanks,
Jim.
I'm writing a simple application which pings a range of IP addresses from a database, and simply records the result back into a table.
I initially wrote it as a console app and everything worked fine. Now that I've converted the code to run as a service it throws a socket error:
VB.NET:
System.Net.NetworkInformation.PingException: An exception occurred during a Ping request. ---> System.Net.Sockets.SocketException: No such host is known
at System.Net.Dns.GetAddrInfo(String name)
at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
--- End of inner exception stack trace ---
at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
I'm confused, because it looks like it's failing a DNS lookup, but I'm passing it an IP address, not a host name. Is this some security setting that's different because the app runs as a service? Its running as my network account which has admin rights.
Here is the sub which performs the ping...
VB.NET:
Private Sub ping(ByVal Address As String)
Dim _ping As New System.Net.NetworkInformation.Ping()
Dim _options As New PingOptions()
Dim _reply As PingReply
myCore.log("Trying: " & Address)
Dim time As Long = 0
Dim hits As Integer = 0
AvgTime = -1
PacketLoss = 100
Dim data As String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" '32 Bytes
Dim buffer As Byte()
buffer = System.Text.Encoding.ASCII.GetBytes(data)
Try
_reply = _ping.Send(Address, 500, buffer, _options)
myCore.log(_reply.Status)
myCore.log(_reply.Address.ToString)
time += _reply.RoundtripTime
hits += 1
AvgTime = time / hits
PacketLoss = ((5 - hits) / hits) * 100
Catch ex As Exception
myCore.log("Error: " & Environment.NewLine & ex.ToString)
End Try
End Sub
Any help would be appreciated as this is starting to get frustrating!
Thanks,
Jim.
Last edited: