Skip to content

Instantly share code, notes, and snippets.

@sciguy16
Forked from eighthave/find-https-debian-archives.py
Last active September 20, 2017 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sciguy16/5550ed4782613313e5cc93c9a8fbdcd0 to your computer and use it in GitHub Desktop.
Save sciguy16/5550ed4782613313e5cc93c9a8fbdcd0 to your computer and use it in GitHub Desktop.
Script to find official Debian mirrors that support HTTPS
#!/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()
@sciguy16
Copy link
Author

Updated the exception catching to catch certificate errors as some of the mirrors have dodgy certs

@sciguy16
Copy link
Author

Also now catches HTTP errors (4**, 5**) rather than failing on broken repo links

@sciguy16
Copy link
Author

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