Skip to content

Instantly share code, notes, and snippets.

@d33tah
Last active January 28, 2016 21:17
Show Gist options
  • Save d33tah/1c45a8cdf456a8782c95 to your computer and use it in GitHub Desktop.
Save d33tah/1c45a8cdf456a8782c95 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import subprocess
import re
fname = 'debian/dists/testing/main/binary-amd64/Packages.xz'.replace('/', '_')
cmd = """
curl http://ftp.vectranet.pl/debian/dists/testing/main/binary-amd64/Packages.xz | \
xzcat > """ + fname
if not os.path.exists(fname):
subprocess.call(cmd, shell=True)
net_pkgs = []
for line in open(fname):
line = line.rstrip('\r\n')
if line.startswith('Package: '):
pkgname = line[len('Package: '):]
if line == 'Section: net':
net_pkgs += [pkgname]
print(net_pkgs)
def get_ports():
cmd = 'nmap localhost -oG - -p- -Pn -n'
l = subprocess.check_output(cmd, shell=True).split('\n')
return {int(x) for x in re.findall(' (\d+)/', l[2])}
clean_ports = get_ports()
l = open("log.txt", 'w')
for n, pkg in enumerate(net_pkgs, 1):
l.write('>%d/%d: %s\n' % (n, len(net_pkgs), pkg))
l.flush()
if pkg == 'nmap':
continue
subprocess.call(['apt-get', 'install', '-y', pkg])
new_ports = get_ports()
if new_ports.difference(clean_ports) != set():
l.write('<%s\n' % new_ports.difference(clean_ports))
subprocess.call(['apt-get', 'remove', '-y', pkg])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment