# Copyright (c) 2010-2012 by Stephan Huebner # # Intended use: # # Set ip-setting to the correct external IP whenever one connects to a server # (so that dcc-sending works) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # History: # v 0.1 - first public release # v 0.2 - changed server from which the IP is gathered # - switched from Pythons' urlopen to weechats' url transfer # (therefore 0.3.7 is required) # - some small tweaks in description and (hopefully) and # IP-checking, to make sure that I really got a correct one. # - changed contact Email to one that actually exists :) # v 0.3 - add option to change service from which the IP is gathered # - better recognition of ipv4 addresses and support of ipv6 # - add mute option # v 0.4 - check if xfer plugin is loaded. SCR_NAME = "xfer_setip" SCR_AUTHOR = "Stephan Huebner " SCR_VERSION = "0.4" SCR_LICENSE = "GPL3" SCR_DESC = "Set apropriate xfer-option for external ip" SCR_COMMAND = "xfer_setip" import_ok = True ip_from_option = 0 OPTIONS = { 'mute' : ('off','hide output'), 'url' : ('http://checkip.dyndns.org/','url to fetch'), } try: import weechat as w from HTMLParser import HTMLParser import re except: print "Script must be run under weechat. http://www.weechat.org" import_ok = False def alert(myString): w.prnt("", myString) return # create a subclass and override the handler methods class MyHTMLParser(HTMLParser): def handle_data(self, data): global OPTIONS, ip_from_option data=data.strip() ipv6 = re.compile(r""" \s* # Leading whitespace (?!.*::.*::) # Only a single whildcard allowed (?:(?!:)|:(?=:)) # Colon iff it would be part of a wildcard (?: # Repeat 6 times: [0-9a-f]{0,4} # A group of at most four hexadecimal digits (?:(?<=::)|(?