forked from sopel-irc/sopel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathip.py
53 lines (48 loc) · 1.8 KB
/
ip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# coding=utf-8
"""
ip.py - jenni IP Lookup Module
Copyright 2011, Dimitri Molenaars, TyRope.nl
Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
"""
import re, web
def ip(jenni, input):
"""IP Lookup tool"""
if not input.group(2):
return jenni.reply("No search term.")
query = input.group(2).encode('utf-8')
uri = 'http://www.rscript.org/lookup.php?type=ipdns&ip='
answer = web.get(uri + web.urllib.quote(query.replace('+', '%2B')))
if answer:
invalid = re.search("(?:INVALID: )([\S ]*)", answer)
if invalid:
response = "[IP/Host Lookup] "+invalid.group(1)
else:
#parse stuffs.
host = re.search("(?:Hostname:[ ]?)([\S ]*)", answer)
isp = re.search("(?:ISP:[ ]?)([\S ]*)", answer)
org = re.search("(?:Organization:[ ]?)([\S ]*)(?:Services:)", answer)
typ = re.search("(?:Type:[ ]?)([\S ]*)", answer)
assign = re.search("(?:Assignment:[ ]?)([\S ]*)", answer)
city = re.search("(?:City:[ ]?)([\S ]*)", answer)
state = re.search("(?:State/Region:[ ]?)([\S ]*)", answer)
country = re.search("(?:Country:[ ]?)([\S ]*)(?: )", answer)
if not host or not isp or not org or not typ or not assign or not city or not state or not country:
response = "[IP/Host Lookup] Something went wrong, please try again."
else:
response = "[IP/Host Lookup] Hostname: "+host.group(1)
response += " | ISP: "+isp.group(1)
response += " | Organization: "+org.group(1)
response += " | Type: "+typ.group(1)
response += " | Assignment: "+assign.group(1)
response += " | Location: "+city.group(1)
response += ", "+state.group(1)
response += ", "+country.group(1)+"."
jenni.say(response)
else:
jenni.reply('Sorry, no result.')
ip.commands = ['iplookup','ip']
ip.example = '.iplookup 8.8.8.8'
if __name__ == '__main__':
print __doc__.strip()