plugins/disabled/dns_plugin.py
author Mikael Berthe <mikael@lilotux.net>
Tue, 01 May 2007 23:59:21 +0200
changeset 17 069f7fd5545d
parent 0 93b25987d3e5
permissions -rw-r--r--
Fix permissions
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     1
#$ neutron_plugin 01
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     2
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     3
import socket
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     4
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     5
def dns_query(query):
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     6
	try:
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     7
		int(query[-1])
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     8
	except ValueError:
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     9
		try:
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    10
			return socket.gethostbyname(query)
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    11
		except socket.gaierror:
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    12
			return 'Unable to Resolve'
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    13
	else:
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    14
		try:
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    15
			(hostname, aliaslist, ipaddrlist) = socket.gethostbyaddr(query)
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    16
		except socket.herror:
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    17
			return 'Unable to Resolve'
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    18
		return hostname + ' ' + string.join(aliaslist) + ' ' + string.join(aliaslist)
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    19
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    20
def handler_dns_dns(type, source, parameters):
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    21
	if parameters.strip():
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    22
		result = dns_query(parameters)
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    23
		smsg(type, source, result)
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    24
	else:
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    25
		smsg(type, source, 'Invalid Syntax')
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    26
93b25987d3e5 Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    27
register_command_handler(handler_dns_dns, '!dns', 0, 'Returns the DNS lookup for a host or IP address.', '!dns <host/IP>', ['!dns jabber.org', '!dns 127.0.0.1'])