我尝试编写一组函数来检查域名的到期日期:
(ql:quickload 'inferior-shell)
(defun whois-lookup (site)
(let ((request (format nil "whois ~a" site)))
(inferior-shell:run/ss request)))
(defun match-expiration-string (input)
(let ((test-string "Registrar Registration Expiration Date:"))
(string> input test-string)))
(defun domain-expiration-date (site)
(with-input-from-string (input (whois-lookup site))
(loop for line = (read-line input nil nil)
while line do
(when (match-expiration-string line)
(format t "~A~%~t~A ~%" site line)))))
我会这样称呼:(domain-expiration-date "startpage.com")
。
不幸的是,它不是仅仅显示相关的行,而是显示所有这些行。
match-expiration-string
似乎工作正常,所以我不知道问题是什么。
CL-USER> (match-expiration-string "Registrar Registration Expiration Date: 2016-05")
39 (6 bits, #x27, #o47, #b100111)
CL-USER> (match-expiration-string "Registrar Registration Expiration ")
NIL
答案 0 :(得分:2)
正如jkiiski所建议的,它适用于正则表达式:
(defun match-expiration-string (input)
(let ((test-string "Registrar Registration Expiration Date:"))
(ppcre:scan test-string input)))
==>
CL-USER> (domain-expiration-date "startpage.com")
startpage.com
Registrar Registration Expiration Date: 2018-10-10T04:00:00Z
NIL
就像约书亚·泰勒所说,你不需要正则表达式,只需要search
。我还注意到“注册商注册过期日期:”并不是每个whois响应,所以我修改了搜索(并且在我需要其他类型域的其他搜索字符串的情况下进行了调整):
(defun match-expiration-string (input)
(let ((inclusion-strings '("Expiration Date:"))
(exclusion-strings '("Registrar Registration Expiration Date:")))
(when (some #'(lambda (s) (search s input))
inclusion-strings)
(notany #'(lambda (s) (search s input))
exclusion-strings))))