Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for whoiscls.vbs

(view source code of whoiscls.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim objDomain
  4.  
  5. Set objDomain = New WhoIs
  6.  
  7. objDomain.Debug          = False
  8. objDomain.DomainName     = "youtube.com"
  9. objDomain.ConnectTimeOut = 25
  10. objDomain.Query
  11.  
  12. WScript.Echo "Whois Version     : " & objDomain.Version
  13. WScript.Echo "Domain Name       : " & objDomain.DomainName
  14. If objDomain.ErrorNumber = 0 Then
  15. 	WScript.Echo "Registrar         : " & objDomain.Registrar
  16. 	WScript.Echo "Whois Server      : " & objDomain.WhoisServer
  17. 	WScript.Echo "Referral URL      : " & objDomain.ReferralURL
  18. 	WScript.Echo "Name Servers      : " & objDomain.NameServers
  19. 	WScript.Echo "Status            : " & objDomain.Status
  20. 	WScript.Echo "Creation Date     : " & objDomain.CreationDate
  21. 	WScript.Echo "Last Updated      : " & objDomain.DateUpdated
  22. 	WScript.Echo "Expiration Date   : " & objDomain.ExpirationDate
  23. Else
  24. 	WScript.Echo "Error Number      : " & objDomain.ErrorNumber
  25. 	WScript.Echo "Error Description : " & objDomain.ErrorDescription
  26. 	WScript.Echo "Error Source      : " & objDomain.ErrorSource
  27. End If
  28.  
  29. Set objDomain = Nothing
  30.  
  31.  
  32. Class WhoIs
  33. ' This class uses Network Solutions, Inc.'s Whois page to
  34. ' retrieve information for .com, .org, and .net domains.
  35. ' Note that this class will break as soon as Network Solutions
  36. ' alters the layout of the Whois results pages.
  37. '
  38. ' Properties:
  39. ' DomainName       R/W [string]  domain name to be queried, e.g. "google.com"
  40. ' ConnectTimeOut   R/W [integer] time-out in seconds, default 15
  41. ' CreationDate     R   [date]    creation date of the whois record
  42. ' DateUpdated      R   [date]    date of the whois record's last update
  43. ' Debug            R/W [boolean] if TRUE, Internet Explorer window will become
  44. '                                and remain visible, and will not be terminated
  45. ' ErrorDescription R   [string]  a short description of the error that occurred
  46. ' ErrorNumber      R   [integer] 0: ok, 462: connection error or time-out,
  47. '                                10001: query error, 10002: can't handle return
  48. '                                format (as in .edu domains)
  49. ' ErrorSource      R   [string]  a short description of the source of the error
  50. ' ExpirationDate   R   [date]    expiration date of the whois record
  51. ' NameServers      R   [string]  comma separated list of DNS servers
  52. ' ReferralURL  **  R   [string]  URL of registrar's website
  53. ' Registrar        R   [string]  company name of registrar
  54. ' Status           R   [string]  comma separated list of domain registry flags
  55. ' Version          R   [string]  version number of this class
  56. ' WhoisServer  **  R   [string]  hostname of the registrar's whois server
  57. ' **                             property empty for .org domains
  58. '
  59. ' Method:
  60. ' Query( )         start the query for the domain specified by DomainName
  61. '
  62. ' Change Log:
  63. ' May 5, 2007      Added Debug, ErrorNumber, ErrorDescription, ErrorSource
  64. '                  and Version properties, fixed errors in .org domain handling
  65. ' April 28, 2007   First public release
  66. '
  67. ' Written by Rob van der Woude
  68. ' http://www.robvanderwoude.com
  69.  
  70. 	' Declare all our private, or local, variables
  71. 	Private arrLine, arrStatus, arrString, arrText, blnTimedOut
  72. 	Private colMatches, i, objIE, objRE, strStatus, strString, x
  73. 	Private m_ConnectTimeOut, m_CreationDate, m_Debug, m_ErrorNumber
  74. 	Private m_ErrorDescription, m_ErrorSource, m_DateUpdated
  75. 	Private m_DomainName, m_ExpirationDate, m_NameServers
  76. 	Private m_ReferralURL, m_Registrar, m_Status, m_Version, m_WhoisServer
  77.  
  78.  
  79. 	' Initialize the variables when the class is initialized
  80. 	Private Sub Class_Initialize
  81. 		blnTimedOut        = False
  82. 		i                  = 0
  83. 		m_ConnectTimeOut   = 10
  84. 		m_CreationDate     = vbNull
  85. 		m_DateUpdated      = vbNull
  86. 		m_Debug            = False
  87. 		m_DomainName       = ""
  88. 		m_ErrorNumber      = 0
  89. 		m_ErrorDescription = ""
  90. 		m_ErrorSource      = ""
  91. 		m_ExpirationDate   = vbNull
  92. 		m_NameServers      = ""
  93. 		m_ReferralURL      = ""
  94. 		m_Registrar        = ""
  95. 		m_Status           = ""
  96. 		m_Version          = "1.10"
  97. 		m_WhoisServer      = ""
  98. 		strString          = ""
  99. 	End Sub
  100.  
  101.  
  102. 	' Get the ConnectTimeOut value
  103. 	Public Property Get ConnectTimeOut
  104. 		ConnectTimeOut = m_ConnectTimeOut
  105. 	End Property
  106.  
  107.  
  108. 	' Set the ConnectTimeOut value
  109. 	Public Property Let ConnectTimeOut( myTimeOut )
  110. 		If IsNumeric( myTimeOut ) Then
  111. 			m_ConnectTimeOut = CInt( myTimeOut )
  112. 		Else
  113. 			m_ConnectTimeOut = 0
  114. 			Err.Raise 5
  115. 		End If
  116. 	End Property
  117.  
  118.  
  119. 	' Get the CreationDate value (read-only)
  120. 	Public Property Get CreationDate
  121. 		CreationDate = m_CreationDate
  122. 	End Property
  123.  
  124.  
  125. 	' Get the CreationDate value (read-only)
  126. 	Public Property Get DateUpdated
  127. 		DateUpdated = m_DateUpdated
  128. 	End Property
  129.  
  130.  
  131. 	' Get the Debug value
  132. 	Public Property Get Debug
  133. 		Debug = m_Debug
  134. 	End Property
  135.  
  136.  
  137. 	' Set the Debug value
  138. 	Public Property Let Debug( blnDebug )
  139. 		If blnDebug = True Then
  140. 			m_Debug = True
  141. 		Else
  142. 			m_Debug = False
  143. 		End If
  144. 	End Property
  145.  
  146.  
  147. 	' Get the DomainName value
  148. 	Public Property Get DomainName
  149. 		DomainName = m_DomainName
  150. 	End Property
  151.  
  152.  
  153. 	' Set the DomainName value
  154. 	Public Property Let DomainName( myDomain )
  155. 		myDomain = Trim( LCase( myDomain ) )
  156. 		' Check the format of the domain name
  157. 		Set objRE = New RegExp
  158. 		objRE.Global     = False
  159. 		objRE.IgnoreCase = True
  160. 		objRE.Pattern    = "^[a-z][a-z_0-9-]+\.[a-z]{2,8}$"
  161. 		Set colMatches = objRE.Execute( myDomain )
  162. 		If colMatches.Count = 1 Then
  163. 			m_DomainName = myDomain
  164. 		Else
  165. 			m_DomainName = ""
  166. 			Err.Raise 5
  167. 		End If
  168. 		Set colMatches = Nothing
  169. 		Set objRE      = Nothing
  170. 	End Property
  171.  
  172.  
  173. 	' Get the Error Number (read-only)
  174. 	Public Property Get ErrorNumber
  175. 		ErrorNumber = m_ErrorNumber
  176. 	End Property
  177.  
  178.  
  179. 	' Get the Error Description (read-only)
  180. 	Public Property Get ErrorDescription
  181. 		ErrorDescription = m_ErrorDescription
  182. 	End Property
  183.  
  184.  
  185. 	' Get the Error Source (read-only)
  186. 	Public Property Get ErrorSource
  187. 		ErrorSource = m_ErrorSource
  188. 	End Property
  189.  
  190.  
  191. 	' Get the ExpirationDate value (read-only)
  192. 	Public Property Get ExpirationDate
  193. 		ExpirationDate = m_ExpirationDate
  194. 	End Property
  195.  
  196.  
  197. ' Get the NameServers value (read-only)
  198. 	Public Property Get NameServers
  199. 		NameServers = m_NameServers
  200. 	End Property
  201.  
  202.  
  203. 	' Get the ReferralURL value (read-only; empty for .org domains)
  204. 	Public Property Get ReferralURL
  205. 		ReferralURL = m_ReferralURL
  206. 	End Property
  207.  
  208.  
  209. 	' Get the Registrar value (read-only)
  210. 	Public Property Get Registrar
  211. 		Registrar = m_Registrar
  212. 	End Property
  213.  
  214.  
  215. 	' Get the Status value (read-only)
  216. 	Public Property Get Status
  217. 		Status = m_Status
  218. 	End Property
  219.  
  220.  
  221. 	' Get this class' version number (read-only)
  222. 	Public Property Get Version
  223. 		Version = m_Version
  224. 	End Property
  225.  
  226.  
  227. 	' Get the WhoisServer value (read-only; empty for .org domains)
  228. 	Public Property Get WhoisServer
  229. 		WhoisServer = m_WhoisServer
  230. 	End Property
  231.  
  232.  
  233. 	' Retrieve the information from Network Solutions
  234. 	' and set the class' read-only properties accordingly
  235. 	Public Function Query
  236. 		' Open the appropriate NetSol WhoIs URL in
  237. 		' an "invisible" Internet Explorer window
  238. 		Set objIE = CreateObject( "InternetExplorer.Application" )
  239. 		objIE.Visible = m_Debug
  240. 		objIE.Navigate2 "https://www.networksolutions.com/whois/" _
  241. 		              & "registry-data.jsp?domain=" & m_DomainName
  242. 		' Wait till IE is ready
  243. 		Do While objIE.Busy
  244. 			' Wait 0.2 second
  245. 			WScript.Sleep 200
  246. 			i = i + 1
  247. 			' Time out after the number of seconds
  248. 			' specified by the ConnectTimeOut property
  249. 			If i > m_ConnectTimeOut * 5 Then
  250. 				blnTimedOut = True
  251. 				Exit Do
  252. 			End If
  253. 		Loop
  254. 		' Retrieve the URL's text and save it in an array
  255. 		If Not blnTimedOut Then
  256. 			arrText = Split( objIE.Document.Body.InnerText, vbCrLf )
  257. 		End If
  258. 		' Unless Debug is True, close the Internet Explorer session
  259. 		If Not m_Debug Then objIE.Quit
  260. 		Set objIE = Nothing
  261. 		' Check if a time-out occurred, and return the result
  262. 		If blnTimedOut = False Then
  263. 			For i = 0 To UBound( arrText )
  264. 				' Filter out the lines starting with 3 spaces
  265. 				Set objRE = New RegExp
  266. 				objRE.Global     = False
  267. 				objRE.IgnoreCase = True
  268. 				If LCase( Right( m_DomainName, 4 ) ) = ".org" Then
  269. 					objRE.Pattern = "^[a-z ]+:.{5,}"
  270. 				Else
  271. 					objRE.Pattern = "^ +[a-z ]+: .{5,}"
  272. 				End If
  273. 				Set colMatches = objRE.Execute( arrText(i) )
  274. 				If colMatches.Count = 1 Then
  275. 					arrLine = Split( arrText(i), ":" )
  276. 					Select Case Trim( LCase( arrLine(0) ) )
  277. 						Case "registrar"
  278. 							arrString = Split( LCase( Trim( arrLine(1) ) ) )
  279. 							For x = 0 To UBound( arrString )
  280. 								strString = strString & " " _
  281. 								          & UCase( Left( arrString(x), 1 ) ) _
  282. 								          & Mid( arrString(x), 2 )
  283. 							Next
  284. 							m_Registrar = Trim( strString )
  285. 						Case "sponsoring registrar"
  286. 							m_Registrar = Trim( Split( arrLine(1), "(" )(0) )
  287. 						Case "whois server"
  288. 							m_WhoisServer = Trim( arrLine(1) )
  289. 						Case "referral url"
  290. 							m_ReferralURL = Trim( arrLine(1) ) & ":" _
  291. 							              & Trim( arrLine(2) )
  292. 						Case "name server"
  293. 							If m_NameServers = "" Then
  294. 								m_NameServers = LCase( Trim( arrLine(1) ) )
  295. 							Else
  296. 								m_NameServers = m_NameServers & "," _
  297. 								              & LCase( Trim( arrLine(1) ) )
  298. 							End If
  299. 						Case "status"
  300. 							strStatus = Trim( arrLine(1) )
  301. 							If InStr( strStatus, " " ) Then
  302. 								arrStatus = Split( LCase( strStatus ), " " )
  303. 								strStatus = arrStatus(0) _
  304. 								          & UCase( Left( arrStatus(1), 1 ) ) _
  305. 								          & Mid( arrStatus(1), 2 ) _
  306. 								          & UCase( Left( arrStatus(2), 1 ) ) _
  307. 								          & Mid( arrStatus(2), 2 )
  308. 							End If
  309. 							If m_Status = "" Then
  310. 								m_Status = Trim( strStatus )
  311. 							Else
  312. 								m_Status = m_Status & "," _
  313. 								         & Trim( strStatus )
  314. 							End If
  315. 						Case "updated date"
  316. 							m_DateUpdated = CDate( Trim( arrLine(1) ) )
  317. 						Case "last updated on"
  318. 							m_DateUpdated = CDate( Trim( Split( arrLine(1), " " )(0) ) )
  319. 						Case "creation date"
  320. 							m_CreationDate = CDate( Trim( arrLine(1) ) )
  321. 						Case "created on"
  322. 							m_CreationDate = CDate( Trim( Split( arrLine(1), " " )(0) ) )
  323. 						Case "expiration date"
  324. 							If LCase( Right( m_DomainName, 4 ) ) = ".org" Then
  325. 								m_ExpirationDate = CDate( Trim( Split( arrLine(1), " " )(0) ) )
  326. 							Else
  327. 								m_ExpirationDate = CDate( Trim( arrLine(1) ) )
  328. 							End If
  329. 					End Select
  330. 				End If
  331. 				Set colMatches = Nothing
  332. 				Set objRE      = Nothing
  333. 			Next
  334. 			If m_Registrar = "" Then
  335. 				If Trim( arrText(1) ) = m_DomainName Then
  336. 					m_ErrorNumber      = 10001
  337. 					m_ErrorDescription = "Unable to extract domain registry info."
  338. 					m_ErrorSource      = "Whois Class " & m_Version
  339. 				Else
  340. 					m_ErrorNumber      = 10002
  341. 					m_ErrorDescription = Trim( arrText(1) )
  342. 					m_ErrorSource      = Trim( arrText(0) )
  343. 				End If
  344. 			End If
  345. 		Else
  346. 			m_ErrorNumber      = 462
  347. 			m_ErrorDescription = "The connection timed out. " _
  348. 			                   & "The remote server machine does " _
  349. 			                   & "not exist or is unavailable."
  350. 			If m_ConnectTimeOut < 45 Then
  351. 				m_ErrorDescription = m_ErrorDescription _
  352. 				                   & " Try a longer time-out interval."
  353. 			End If
  354. 			m_ErrorSource      = "Internet Explorer connection time-out"
  355. 		End If
  356. 	End Function
  357. End Class
  358.  

page last uploaded: 2017-07-06, 12:37