# -*- coding: utf-8  -*-

#
# Modified from: https://it.wikipedia.org/wiki/Utente:BimBot/Scripts#discussioneanonimi3.py
#

import pywikibot, re

args = pywikibot.handleArgs()
site = pywikibot.Site('it', 'wikipedia')

def main():
    talkpages = pywikibot.Page(site, u'Wikipedia:Elenchi generati offline/Discussioni utenti anonimi').linkedPages();
    for talk in talkpages:
        static=False
        if talk.namespace() != 3 or not talk.exists() or not talk.canBeEdited():
            continue
        pywikibot.output(">>>>> " + talk.title() + " <<<<<")

        oldtext = talk.get()

        if checkStatic(talk.titleWithoutNamespace()):
            newtext = oldtext + u'\n[[Categoria:IP statici]]'
            pywikibot.showDiff(oldtext, newtext)
	    pywikibot.setAction(u'Bot: categorizzo in [[:Categoria:IP statici]]')
            talk.put(newtext)
        else:
            newtext = u'{{BenvenutoIP}}'
            match = re.search("\{\{IPcondiviso.*?\}\}", oldtext)
            if match != None:
                newtext = match.group() + '\n' + newtext
            pywikibot.showDiff(oldtext, newtext)
	    pywikibot.setAction(u'Bot: svuotata pagina ed inserito benvenuto')
            talk.put(newtext)

def checkStatic(ip):
    response = commands.getoutput("dig -x " + ip + " +short")
    pywikibot.output('Dig response: ' + response)
    return bool(re.search('[Ss]tatic', response))

if __name__ == "__main__":
    try:
        main()

@@ -136,16 +136,93 @@
 ibot, re
+, commands%0Afrom time import *%0A%0Aos.environ%5B'TZ'%5D = 'Europe/Rome'%0Ainizio=time()
 %0A%0Aargs =
@@ -696,15 +696,13 @@
 itle
-W
+(w
 ith
-out
 Name
@@ -706,17 +706,22 @@
 amespace
-(
+=False
 )):%0A    
@@ -1526,8 +1526,79 @@
  main()%0A
+    finally:%0A       fine=time()%0A       print %22Run time: %22, fine-inizio%0A

Fix talk_ip.py