-
Notifications
You must be signed in to change notification settings - Fork 5
/
test-mirrors-ip.py
executable file
·72 lines (56 loc) · 1.38 KB
/
test-mirrors-ip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python
#
# This is a Python script that tests mirrors to see if there are any
# duplicates within.
#
# The first argument should be the path to the mirror database (e.g.
# mirrors.list).
import sys
import string
import os
import re
import socket
verbose = 0
timeout = 10
ips= {}
error = __name__ + '.error'
class MirrorError (Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return `self.value`
try:
sys.argv[1]
except IndexError:
print "Usage: " + sys.argv[0] + " <mirror-database>"
sys.exit(0)
if verbose:
print "Opening mirror database " + sys.argv[1] + "..."
f = open(sys.argv[1])
lines = f.readlines()
for line in lines:
line = string.strip(line)
splitline = string.split(line)
mcountry = splitline[0]
p = re.compile(r'^(f|ht)tp://(?P<hn>[^/]*)/?.*$')
m = p.search(splitline[1])
mname = m.group('hn')
if verbose:
print "Checking mirror " + mname + " [" + mcountry + "]..."
try:
mip = socket.gethostbyname_ex(mname)[2][0]
except (socket.error, socket.gaierror):
raise MirrorError, "Unable to determine IP address"
if verbose:
print "Got IP address: " + mip
if mip in ips:
ips[mip]=ips[mip] + " " + mname
else:
ips[mip]=mname
for ip in ips:
names=ips[ip].split()
if len(names)>1:
print "Duplicate IP found: " + ip
for name in names:
print "\t" + name
sys.exit()