home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / open_WinDN554542152002.psc / Module1.bas < prev    next >
Encoding:
BASIC Source File  |  2002-02-12  |  9.8 KB  |  300 lines

  1. Attribute VB_Name = "Module1"
  2.  
  3. Public Function outPuta(inputAsInt As String) As String
  4. On Error GoTo ender
  5. ' the input from query as integers
  6. Dim eachInputInt() As String
  7. ' split apart each integer to handle
  8. Dim domainString As String
  9. 'domain requested for
  10. Dim domainBin As String
  11. 'original domain query
  12. Dim pointAt As Integer
  13. 'keep position of int
  14. Dim requestType As String
  15. 'type of request, mx , A
  16. Dim typeOfType As String
  17. 'type of request inet..
  18. inputAsInt = Mid(inputAsInt, 2, Len(inputAsInt))
  19. 'slice down first space
  20. eachInputInt = Split(inputAsInt, " ")
  21. 'split up the ints
  22. startstring = Chr(eachInputInt(0)) & Chr(eachInputInt(1))
  23. 'when replying it must have the same start
  24. pointAt = 12
  25. 'skip to beginning of domain
  26. Do While pointAt < UBound(eachInputInt)
  27. length = eachInputInt(pointAt)
  28. 'since DNS does not like using periods it instead uses length of section
  29. If length = 0 Then Exit Do
  30. 'ok done with domain
  31. If domainBin = "" Then domainBin = domainBin & Chr(eachInputInt(pointAt))
  32. For i = 1 To length
  33. domainString = domainString & Chr(eachInputInt(pointAt + i))
  34. domainBin = domainBin & Chr(eachInputInt(pointAt + i))
  35. Next i
  36. 'add all characters up to that length (next period or end)
  37. pointAt = pointAt + length + 1
  38. 'move position holder to next period or end
  39. If Not eachInputInt(pointAt) = 0 Then
  40. 'not end
  41. domainBin = domainBin & Chr(eachInputInt(pointAt))
  42. domainString = domainString & "."
  43. End If
  44. Loop
  45. pointAt = pointAt + 2
  46. 'skip to the query type, mx or A, etc...
  47. requestType = eachInputInt(pointAt)
  48.  
  49. pointAt = pointAt + 2
  50. 'skip to type such as inet
  51. typeOfType = eachInputInt(pointAt)
  52. ''''' time to make reply
  53. Dim reply As String
  54.  
  55. Dim domainAnswer As String
  56. Dim domainSection As String
  57. Dim prefEr As String
  58. 'preference/priority
  59. reply = startstring
  60. If Not isDomainHosted(domainString) Then reply = reply & Chr(0) & Chr(0) & Chr(0): GoTo ender
  61. 'set the start to the same
  62. reply = reply & Chr(133) & Chr(128)
  63. 'i dont know what the hell this does
  64. reply = reply & Chr(0) & Chr(1)
  65. 'says it is answering one query
  66. reply = reply & Chr(0) & Chr(1)
  67. 'says it has found these many answers
  68. reply = reply & Chr(0) & Chr(0)
  69. 'says it has found these ns servers
  70. reply = reply & Chr(0) & Chr(0)
  71. 'says how many extra things there are
  72. reply = reply & domainBin
  73. 'say the domain you are replying to
  74. reply = reply & Chr(0) & Chr(0)
  75. 'blank space
  76. reply = reply & Chr(requestType) & Chr(0)
  77. 'telling the reply type
  78. reply = reply & Chr(1) & Chr(192) & Chr(12)
  79. 'the first part identifies how many resuls, the second and third part identifies the pointer char and where the domain starts
  80. reply = reply & Chr(0) & Chr(requestType)
  81. 'tell it the request type mx, a, etc...
  82. reply = reply & Chr(0) & Chr(typeOfType)
  83. Select Case requestType
  84. Case 1
  85. reply = reply & Chr(0) & Chr(0)
  86. 'tell it the RR Class (whatever that shit is)
  87. reply = reply & Chr(81) & Chr(129) & Chr(0)
  88. 'time to live ... dont know how it is formated
  89. 'now we have to format the answer... which is a biatch so lets get started
  90. reply = reply & lookUpIP(domainString) & Chr(0)
  91. 'reply = reply & Chr(4) & Chr(24) & Chr(189) & Chr(121) & Chr(87)
  92. 'MsgBox lookUpIP(domainString)
  93. Case 15
  94. 'tell it the stupid type inet
  95. reply = reply & Chr(0) & Chr(1)
  96. 'tell it the RR Class (whatever that shit is)
  97. reply = reply & Chr(81) & Chr(129)
  98. 'time to live ... dont know how it is formated
  99. 'now we have to format the answer... which is a biatch so lets get started
  100. domainAnswer = domainCompressed(domainString, lookUpMX(domainString, prefEr))
  101.  
  102. 'compressed mx answer
  103. domainSection = Chr(Len(domainAnswer))
  104. 'number of octets taken up by answer
  105. reply = reply & Chr(0) & domainSection
  106. 'tell the number of octets
  107. reply = reply & Chr(0) & Chr(Int(prefEr))
  108. 'priority
  109. reply = reply & domainAnswer
  110. reply = reply & Chr(0)
  111. End Select
  112. ender:
  113. outPuta = reply
  114.  
  115. End Function
  116. Public Function domainCompressed(domainString As String, mxString As String) As String
  117. If mxString = domainString Then
  118.     domainCompressed = Chr(192) & Chr(12)
  119.     Exit Function
  120. End If
  121. Dim mxCopy As String
  122. mxCopy = mxString
  123. Dim mxDomainArry() As String
  124. Dim finalDomain As String
  125. Dim mxHold As String
  126. Dim dmHold As String
  127. Dim findPeriodM As Integer
  128. Dim findPeriodD As Integer
  129. Dim periodCountM As Integer
  130. Dim periodCountD As Integer
  131. Dim periodLocM As String
  132. Dim periodLocD As String
  133. Dim periodArryM() As String
  134. Dim periodArryD() As String
  135.  
  136. periodCountM = 0
  137. periodCountD = 0
  138. findPeriodM = 0
  139. findPeriodD = 0
  140.  
  141. While Not InStr(findPeriodD + 1, domainString, ".") < 1
  142.     findPeriodD = InStr(findPeriodD + 1, domainString, ".")
  143.     If Not periodLocD = "" Then
  144.         periodLocD = periodLocD & " " & findPeriodD
  145.     Else
  146.         periodLocD = findPeriodD
  147.     End If
  148.     periodCountD = periodCountD + 1
  149. Wend
  150. periodArryD = Split(periodLocD, " ")
  151.  
  152. While Not InStr(findPeriodM + 1, mxString, ".") < 1
  153.     findPeriodM = InStr(findPeriodM + 1, mxString, ".")
  154.     If Not periodLocM = "" Then
  155.         periodLocM = periodLocM & " " & findPeriodM
  156.     Else
  157.         periodLocM = findPeriodM
  158.     End If
  159.     periodCountM = periodCountM + 1
  160. Wend
  161. periodArryM = Split(periodLocM, " ")
  162.  
  163.  
  164. For m = -1 To UBound(periodArryD)
  165.     For i = -1 To UBound(periodArryM)
  166.     trueBubble = False
  167.         For z = UBound(periodArryM) + 1 To i + 1 Step -1
  168.         If m = -1 Then
  169.             dmHold = domainString
  170.         Else
  171.             dmHold = Mid(domainString, periodArryD(m) + 1, Len(domainString) - periodArryD(m))
  172.         End If
  173.         If i = -1 And z = UBound(periodArryM) + 1 Then
  174.             mxHold = mxString
  175.             
  176.         ElseIf i = -1 And Not z = UBound(periodArryM) + 1 Then
  177.             mxHold = Mid(mxString, 1, periodArryM(z) - 1)
  178.             
  179.         ElseIf Not i = -1 And z = UBound(periodArryM) + 1 Then
  180.             mxHold = Mid(mxString, periodArryM(i) + 1, Len(mxString) - periodArryM(i))
  181.             
  182.         Else
  183.             mxHold = Mid(mxString, periodArryM(i) + 1, periodArryM(z) - (periodArryM(i) + 1))
  184.             
  185.         End If
  186.         If mxHold = dmHold Then mxCopy = Replace(mxCopy, mxHold, Chr(192 + 11 + Int(InStr(1, domainString, mxHold))))
  187.         Next z
  188.     Next i
  189.  
  190. Next m
  191. Dim good As String
  192. Dim whoaPeriodLength() As String
  193. whoaPeriodLength = Split(mxCopy, ".")
  194. Dim whoaPeriods As Integer
  195. good = Chr(Len(whoaPeriodLength(0)))
  196. whoaPeriods = 1
  197. For i = 1 To Len(mxCopy)
  198. If Not Asc(Mid(mxCopy, i, 1)) > 192 And Not Mid(mxCopy, i, 1) = "." Then
  199. good = good & Mid(mxCopy, i, 1)
  200. 'End If
  201. ElseIf Mid(mxCopy, i, 1) = "." And Not i = Len(mxCopy) - 1 Then
  202. If Not Asc(Mid(mxCopy, i + 1, 1)) > 192 Then
  203.     good = good & Chr(Len(whoaPeriodLength(whoaPeriods)))
  204.     whoaPeriods = whoaPeriods + 1
  205.     Else
  206.     whoaPeriods = whoaPeriods + 1
  207.     End If
  208. ElseIf Mid(mxCopy, i, 1) = "." And i = Len(mxCopy) - 1 Then
  209. whoaPeriods = whoaPeriods + 1
  210.  
  211. 'End If
  212. ElseIf Asc(Mid(mxCopy, i, 1)) > 192 And Not i = Len(mxCopy) Then
  213. good = good & Chr(192) & Chr(Asc(Mid(mxCopy, i, 1)) - 192)
  214.  
  215. ElseIf Asc(Mid(mxCopy, i, 1)) > 192 And i = Len(mxCopy) Then
  216. good = good & Chr(192) & Chr(Asc(Mid(mxCopy, i, 1)) - 192) & Chr(192) & Chr(12)
  217. End If
  218. Next i
  219. 'For i = 1 To Len(good)
  220. 'MsgBox Mid(good, i, 1)
  221. 'Next i
  222. domainCompressed = good
  223. End Function
  224. Function isDomainHosted(domainString As String) As Boolean
  225. Dim endPart As String
  226. Dim Broken() As String
  227. If recordDNS.State > 0 Then
  228. recordDNS.Close
  229. End If
  230. Broken = Split(domainString, ".")
  231. endPart = Broken(UBound(Broken) - 1) & "." & Broken(UBound(Broken))
  232.  
  233. recordDNS.Open "select * from DomainList WHERE [Domain Name] = '" & endPart & "';", dataDNS, adOpenKeyset, adLockPessimistic, adCmdText
  234. If recordDNS.EOF Or recordDNS.BOF Then
  235. isDomainHosted = False
  236. Else
  237. isDomainHosted = True
  238. End If
  239. End Function
  240. Function lookUpIP(domainString As String) As String
  241. Dim endPart As String
  242. Dim Broken() As String
  243. Dim preIP As String
  244. Dim ipArry() As String
  245. Dim tablA As String
  246. Dim Answer As String
  247. If recordDNS.State > 0 Then
  248. recordDNS.Close
  249. End If
  250. Broken = Split(domainString, ".")
  251. endPart = Broken(UBound(Broken) - 1) & "." & Broken(UBound(Broken))
  252. recordDNS.Open "select * from DomainList WHERE [Domain Name] = '" & endPart & "';", dataDNS, adOpenKeyset, adLockPessimistic, adCmdText
  253. tablA = recordDNS.Fields("ID")
  254. recordDNS.Close
  255. recordDNS.Open "select * from [" & tablA & "] WHERE Name='" & domainString & "';", dataDNS, adOpenKeyset, adLockPessimistic, adCmdText
  256. If Not recordDNS.EOF And Not recordDNS.BOF Then
  257. happy:
  258. preIP = recordDNS.Fields("IP")
  259. ipArry = Split(preIP, ".")
  260. Answer = Chr(4)
  261. For Each spot In ipArry
  262. Answer = Answer & Chr(spot)
  263. Next
  264. lookUpIP = Answer
  265. Exit Function
  266. End If
  267. recordDNS.Close
  268. recordDNS.Open "select * from [" & tablA & "] WHERE Name='www." & endPart & "';", dataDNS, adOpenKeyset, adLockPessimistic, adCmdText
  269. If Not recordDNS.EOF And Not recordDNS.BOF Then GoTo happy
  270. recordDNS.Close
  271. recordDNS.Open "select * from [" & tablA & "];", dataDNS, adOpenKeyset, adLockPessimistic, adCmdText
  272. If Not recordDNS.EOF And Not recordDNS.BOF Then GoTo happy
  273. lookUpIP = Chr(4) & Chr(0) & Chr(0) & Chr(0) & Chr(0)
  274. End Function
  275. Function lookUpMX(domainString As String, ByRef preF As String) As String
  276. Dim endPart As String
  277. Dim Broken() As String
  278. Dim tablA As String
  279. Dim Answer As String
  280. If recordDNS.State > 0 Then
  281. recordDNS.Close
  282. End If
  283. Broken = Split(domainString, ".")
  284. endPart = Broken(UBound(Broken) - 1) & "." & Broken(UBound(Broken))
  285. recordDNS.Open "select * from DomainList WHERE [Domain Name] = '" & endPart & "';", dataDNS, adOpenKeyset, adLockPessimistic, adCmdText
  286. tablA = recordDNS.Fields("ID")
  287. recordDNS.Close
  288. recordDNS.Open "select * from [" & tablA & "] WHERE type=15;", dataDNS, adOpenKeyset, adLockPessimistic, adCmdText
  289. If recordDNS.EOF Or recordDNS.BOF Then
  290. Answer = "mx1." & endPart
  291. preF = 50
  292. Else
  293. Answer = Trim$(recordDNS.Fields("Name"))
  294. preF = Trim$(recordDNS.Fields("Additional"))
  295. End If
  296. lookUpMX = Answer
  297.  
  298. End Function
  299.  
  300.