home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / languard / languardnss7.exe / portscan.vbs < prev    next >
Encoding:
Text File  |  2005-10-04  |  4.7 KB  |  147 lines

  1. Function GetPatternPart(ByRef p_strPattern, ByRef p_strPatternPart)
  2.   Dim result As Integer
  3.   result = -1
  4.   If p_strPattern = "" Then
  5.     result = 0
  6.   Else
  7.     Select Case  Left(p_strPattern, 1)
  8.       Case "x", "X"
  9.         result = 1
  10.         p_strPattern = Mid(p_strPattern, 2, Len(p_strPattern) - 1) 
  11.       Case "?"
  12.         result = 2
  13.         p_strPattern = Mid(p_strPattern, 2, Len(p_strPattern) - 1) 
  14.       Case "*"
  15.         result = 3
  16.         p_strPattern = Mid(p_strPattern, 2, Len(p_strPattern) - 1) 
  17.       Case "'", "#"
  18.         result = 4
  19.         p_strPatternPart = ""
  20.         If Left(p_strPattern, 1)  = "#" Then
  21.           p_strPattern = Mid(p_strPattern, 2, Len(p_strPattern) - 1) 
  22.           If (p_strPattern <> "") And IsNumeric(Left(p_strPattern, 1)) Then
  23.             Dim code As Integer
  24.             code = CInt(Left(p_strPattern, 1))
  25.             p_strPattern = Mid(p_strPattern, 2, Len(p_strPattern) - 1) 
  26.             If (p_strPattern <> "") And IsNumeric(Left(p_strPattern, 1)) Then
  27.               code  = code * 10 + CInt(Left(p_strPattern, 1))
  28.               p_strPattern = Mid(p_strPattern, 2, Len(p_strPattern) - 1) 
  29.               If (p_strPattern <> "") And IsNumeric(Left(p_strPattern, 1)) Then
  30.                 code  = code * 10 + CInt(Left(p_strPattern, 1))
  31.                 p_strPattern = Mid(p_strPattern, 2, Len(p_strPattern) - 1) 
  32.               End If 
  33.             End If 
  34.             If code > 255 Then
  35.               result = -1
  36.             Else
  37.               p_strPatternPart = p_strPatternPart + Chr(code)  
  38.             End If
  39.           Else
  40.             result  = -1
  41.           End If
  42.         Else
  43.           p_strPattern = Mid(p_strPattern, 2, Len(p_strPattern) - 1) 
  44.           Dim bStringDone As Boolean
  45.           bStringDone = FALSE
  46.           While (p_strPattern <> "") And Not bStringDone
  47.             If Left(p_strPattern, 1) = "'" Then
  48.               bStringDone = TRUE
  49.             Else 
  50.               p_strPatternPart = p_strPatternPart + Left(p_strPattern, 1)
  51.             End If
  52.             p_strPattern = Mid(p_strPattern, 2, Len(p_strPattern) - 1) 
  53.           Wend
  54.           If (p_strPattern = "") And Not bStringDone Then
  55.             result = -1
  56.           End If
  57.         End If
  58.         If p_strPatternPart = "" Then
  59.           result = -1
  60.         End if
  61.     End Select
  62.   End If
  63.   GetPatternPart = result
  64. End Function
  65.  
  66. Function MatchString(p_strPattern, p_strBanner)
  67.   Dim result As Boolean
  68.   result = TRUE
  69.   Dim strPattern As String
  70.   strPattern = p_strPattern
  71.   Dim strBanner As String
  72.   strBanner = p_strBanner
  73.   If strPattern <> "" Then
  74.     Dim bStar As Boolean
  75.     bStar = FALSE
  76.     Dim bEqual As Boolean
  77.     If Left(strPattern, 1)  = "=" Then
  78.       bEqual = TRUE
  79.       strPattern = Mid(strPattern, 2, Len(strPattern) - 1) 
  80.     Else
  81.       bEqual = FALSE
  82.       bStar = TRUE
  83.     End If
  84.     Do While strBanner <> "" 
  85.       Dim patternType As Integer
  86.       Dim strPatternPart As String
  87.       patternType = GetPatternPart(strPattern, strPatternPart)
  88.       Select Case patternType 
  89.         Case 1
  90.           If bStar Then
  91.             bStar = FALSE
  92.             While (strBanner <> "") And Not IsNumeric(Left(strBanner, 1))
  93.               strBanner = Mid(strBanner, 2, Len(strBanner) - 1)
  94.             Wend
  95.             If strBanner = "" Then
  96.               result = FALSE
  97.               Exit Do
  98.             End If
  99.           Else
  100.             If Not IsNumeric(Left(strBanner, 1)) Then
  101.               result = FALSE
  102.               Exit Do
  103.             End If
  104.           End If
  105.           If strBanner <> "" Then
  106.             strBanner = Mid(strBanner, 2, Len(strBanner) - 1)
  107.           End If
  108.         Case 2
  109.           strBanner = Mid(strBanner, 2, Len(strBanner) - 1)
  110.         Case 3
  111.           bStar = TRUE
  112.         Case 4
  113.           Dim nPos As Integer
  114.           nPos = InStr(1, strBanner, strPatternPart)
  115.           If nPos <> 0 Then
  116.             If bStar Then
  117.               bStar = FALSE
  118.               strBanner  = Right(strBanner, Len(strBanner) - (nPos + Len(strPatternPart) - 1))
  119.             Else
  120.               If nPos <> 1 Then
  121.                 result = FALSE
  122.                 Exit Do
  123.               Else
  124.                 strBanner = Right(strBanner, Len(strBanner) - (Len(strPatternPart) - 1))
  125.               End If 
  126.             End If
  127.           Else
  128.             result = FALSE
  129.             Exit Do
  130.           End If
  131.         Case 0
  132.           If bEqual And Not bStar Then
  133.             result = FALSE
  134.           End If
  135.           Exit Do
  136.         Case -1
  137.           result  = FALSE
  138.           Exit Do           
  139.       End Select
  140.     Loop
  141.     If (strBanner = "") And (strPattern <> "") And (strPattern <> "*") Then
  142.       result = FALSE
  143.     End If  
  144.   End If
  145.   MatchString = result  
  146. End Function
  147.