Aggiunta barra per la ricerca.
Leonardo [2010-05-24 13:19]
Aggiunta barra per la ricerca.
diff --git a/pywhois.py b/pywhois.py
index 27dcffe..8914e47 100644
--- a/pywhois.py
+++ b/pywhois.py
@@ -282,9 +282,22 @@ class WhoisHTTPRequestHandler(BaseHTTPRequestHandler):
font-size: 14px;
margin-left: 50px;
}
+
+ form {
+ margin: auto;
+ margin-left: 50px;
+ }
</style>
"""
+ request_form = """
+ <br />
+ <form action="/" method="GET">
+ <input type="text" value="Insert IP or domain" size="80" name="query" />
+ <input type="submit" value="Cerca" />
+ </form>
+ """
+
def SendHeaders(self):
"""
Send headers
@@ -303,6 +316,7 @@ class WhoisHTTPRequestHandler(BaseHTTPRequestHandler):
html += "<body>\n"
html += "<h1>Whois answer for %s</h1>\n<p>" % request
html += re.sub(r"\n", "<br>\n", string)
+ html += self.request_form
html += "</p></body>\n"
html += "</html>"
return html
@@ -312,16 +326,21 @@ class WhoisHTTPRequestHandler(BaseHTTPRequestHandler):
Handler GET request
"""
# Estraiamo la richiesta.
- request = self.path[1:].strip()
+ try:
+ request = re.findall(r"/?query=([^\s]+)", self.path)[0]
+ except:
+ response = "Please submit a query"
+ request = None
# Ci connettiamo al demone locale. Questo è
# decisamente subottimale, ma per ora non ho
# voglia di fare di meglio
- s = socket(AF_INET, SOCK_STREAM)
- s.connect(self.server.whoisserver)
- s.send (request + "\n")
- response = s.recv(1024)
- s.close ()
+ if request:
+ s = socket(AF_INET, SOCK_STREAM)
+ s.connect(self.server.whoisserver)
+ s.send (request + "\n")
+ response = s.recv(1024)
+ s.close ()
# Ok, finalmente ci siamo
self.send_response(200)