# Copyright (c) 2010 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 from urllib2 import urlopen from urllib2 import URLError SCR_NAME = "setip" SCR_AUTHOR = "Stephan Huebner " SCR_VERSION = "0.1" SCR_LICENSE = "GPL3" SCR_DESC = "Set xfer-option for external ip" SCR_COMMAND = "setip" import_ok = True bfList = [] try: import weechat as w except: print "Script must be run under weechat. http://www.weechat.org" import_ok = False settings = { } def errMsg(myMsg): w.prnt("", "ERR: " + myMsg) return def alert(myString): w.prnt("", myString) return def 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_OK def fn_command(data, buffer, args): fn_connected(data, buffer, args) return w.WEECHAT_RC_OK if __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". Once started, 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 should check weechats' core-buffer for messages (the script will output there if the IP had been set or if something went wrong). """, "", "", "fn_command", "" )