Public Shared Function IsBadHost(Ip As String) As Boolean
Dim OK As Boolean = False
Try
Dim Host As String
Dim Hosts As String()
Dim ObjectCache As New MyCache
If Not ObjectCache.MyCacheContains("hosts") Then
'// Check if BotList in Cache, else get it and cache it.
Hosts = GetHostsStringArray(AppDomain.CurrentDomain.BaseDirectory + "BadHostList.xml")
Dim lstFiles As List(Of [String]) = New List(Of String)()
lstFiles.Add(AppDomain.CurrentDomain.BaseDirectory + "BadHostList.xml")
ObjectCache.addToMyCache("hosts", Hosts, MyCachePriority.[Default], lstFiles)
Else
'// Got in cahce
Hosts = DirectCast(ObjectCache.GetMyCachedItem("hosts"), String())
End If
Dim MyHostName As String = System.Net.Dns.GetHostEntry(Ip).HostName.ToString
For Each Host In Hosts
If MyHostName.Contains(Host) Then
Return True
End If
Next
Catch ex As Exception
Errorhandler.ErrorHandler(0, ex.ToString)
End Try
Return OK
End Function
Public Shared Function GetHostsStringArray(path As String) As String()
Dim bots As String() = {}
Try
Dim doc = XDocument.Load(path)
' Select all bot entries
Dim MyServices = From service In doc.Descendants("host") Select service.Value
bots = MyServices.ToArray()
Catch ex As Exception
Errorhandler.ErrorHandler(0, ex.ToString)
End Try
Return bots
End Function