ping test

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
from urllib import urlopen
from xmlrpclib import ServerProxy, Fault
import re
def search_link(content):
match = re.search(r'<link rel="pingback" href="([^"]+)" ?/?>', content)
return match and match.group(1)
url = 'http://it-omsk.com/test.html'
link = 'http://web-brains.com/2008/01/11/rozovyij-popyatchso/'
try:
f = urlopen(link)
server_url = f.info().get('X-Pingback', '') or search_link(f.read(512 * 1024))
if server_url:
server = ServerProxy(server_url)
q = server.pingback.ping(url, link)
print 'result: %s' % q
except (IOError, ValueError, Fault), ex:
print 'Error: %s' % ex