Forked from eighthave/find-https-debian-archives.py
Last active
September 20, 2017 10:41
-
-
Save sciguy16/5550ed4782613313e5cc93c9a8fbdcd0 to your computer and use it in GitHub Desktop.
Script to find official Debian mirrors that support HTTPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import urllib2 | |
import re | |
import ssl | |
import sys | |
# # find generic mirrors | |
mirrors = urllib2.urlopen('http://www.debian.org/mirror/list') | |
https = [] | |
for line in mirrors.readlines(): | |
m = re.match('.*<td valign="top"><a rel="nofollow" href="http(.*)">.*', line) | |
if m: | |
url = 'https' + m.group(1) | |
print 'trying: ', | |
print url, | |
print '...', | |
sys.stdout.flush() | |
try: | |
response=urllib2.urlopen(url, timeout=1) | |
https.append(url) | |
print 'success!' | |
except urllib2.HTTPError as err: | |
print 'HTTP error',err.code | |
except urllib2.URLError as err: | |
print 'fail!' | |
except ssl.SSLError as err: | |
print 'bad SSL!' | |
except ssl.CertificateError as err: | |
print 'bad certificate!' | |
# print 'HTTPS apt repos:' | |
#for url in https: | |
# print url | |
# # find security mirrors | |
mirrors = urllib2.urlopen('http://www.debian.org/mirror/list-full') | |
securitys = [] | |
for line in mirrors.readlines(): | |
m = re.match('.*</tt><br>Security updates over HTTP: <tt><a rel="nofollow" href="http(.*)">.*/debian-security/</a>.*', line) | |
if m: | |
url = 'https' + m.group(1) | |
print 'trying: ', | |
print url, | |
print '...', | |
sys.stdout.flush() | |
try: | |
response=urllib2.urlopen(url, timeout=1) | |
securitys.append(url) | |
print 'success!' | |
except urllib2.URLError as err: | |
print 'fail!' | |
except ssl.SSLError as err: | |
print 'bad SSL!' | |
except ssl.CertificateError as err: | |
print 'bad certificate!' | |
# print 'HTTPS security repos:' | |
# for url in securitys: | |
# print url | |
# now find the CD image mirrors | |
mirrors = urllib2.urlopen('http://www.debian.org/CD/http-ftp/') | |
cds = [] | |
for line in mirrors.readlines(): | |
# <a rel="nofollow" href="http://mirror.easyspeedy.com/debian-cd/">HTTP</a></li> | |
m = re.match('.*<a rel="nofollow" href="http(:.*)">HTTP</a></li>.*', line) | |
if m: | |
url = 'https' + m.group(1) | |
print 'trying: ', | |
print url, | |
print '...', | |
sys.stdout.flush() | |
try: | |
response=urllib2.urlopen(url, timeout=1) | |
cds.append(url) | |
print 'success!' | |
except urllib2.HTTPError as err: | |
print 'HTTP error',err.code | |
except urllib2.URLError as err: | |
print 'fail!' | |
except ssl.SSLError as err: | |
print 'bad SSL!' | |
except ssl.CertificateError as err: | |
print 'bad certificate!' | |
print 'HTTPS CD image repos:' | |
for url in cds: | |
print url | |
# now write everything to a file | |
f = open('/tmp/https-debian-archives.txt', 'w') | |
f.write('HTTPS apt repos\n') | |
f.write('---------------\n') | |
for url in https: | |
f.write(url + '\n') | |
f.write('\n\nHTTPS security repos\n') | |
f.write('---------------\n') | |
for url in securitys: | |
f.write(url + '\n') | |
f.write('\n\nHTTPS CD image repos\n') | |
f.write('--------------------\n') | |
for url in cds: | |
f.write(url + '\n') | |
f.close() |
Also now catches HTTP errors (4**, 5**) rather than failing on broken repo links
Removed backports checks as they have been merged into the main repos
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated the exception catching to catch certificate errors as some of the mirrors have dodgy certs