# Copyright (c) 2010 by Stephan Huebner <s.huebnerfun01@gmx.org>## 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 <http://www.gnu.org/licenses/>.## History:# v 0.1 - first public releasefrom urllib2 import urlopenfrom urllib2 import URLErrorSCR_NAME = "setip"SCR_AUTHOR = "Stephan Huebner <shuebnerfun01@gmx.org>"SCR_VERSION = "0.1"SCR_LICENSE = "GPL3"SCR_DESC = "Set xfer-option for external ip"SCR_COMMAND = "setip"import_ok = TruebfList = []try: import weechat as wexcept: print "Script must be run under weechat. http://www.weechat.org" import_ok = Falsesettings = {}def errMsg(myMsg): w.prnt("", "ERR: " + myMsg) returndef alert(myString): w.prnt("", myString) returndef fn_connected(data, signal, signal_data): try: ext_ip = urlopen("http://whatismyip.org").read() w.command("", "/set xfer.network.own_ip %s" %ext_ip) except URLError: errMsg("URL/IP could not be retrieved!") return w.WEECHAT_RC_OKdef fn_command(data, buffer, args): fn_connected(data, buffer, args) return w.WEECHAT_RC_OKif __name__ == "__main__" and import_ok: if w.register(SCR_NAME, SCR_AUTHOR, SCR_VERSION, SCR_LICENSE, SCR_DESC, "", ""): # hook to "connected to (any) server"-signal w.hook_signal("irc_server_connected", "fn_connected", "") w.hook_command( # help-text SCR_COMMAND, "","""The script tries to retrieve your external IP from "whatismyip.org". Oncestarted, it will do so on two occasions: 1) whenever you have succesfully connected to *any* server (imho, the easiest way to make sure that your IP is set correctly after a (possible) disconnection from the internet). 2) when the script is called itself as a command "/setip".Attention: It seems that the "whatismyip.org" isn't very reliable. You shouldcheck weechats' core-buffer for messages (the script will output there if theIP had been set or if something went wrong).""", "", "", "fn_command", "" )