Skip to content

Instantly share code, notes, and snippets.

@celebdor
Last active March 2, 2018 11:26
Show Gist options
  • Select an option

  • Save celebdor/ada01aef3f1f58942b1694ace9c9ece5 to your computer and use it in GitHub Desktop.

Select an option

Save celebdor/ada01aef3f1f58942b1694ace9c9ece5 to your computer and use it in GitHub Desktop.
# coding: utf-8
import subprocess
import sys
CAP_NET_ADMIN = 12 # Taken from linux/capabilities.h
def am_i_net_admin():
with open('/proc/self/status', 'r') as pstat:
for line in pstat:
if line.startswith('CapEff:\t'):
caps = int(line[len('CapEff:\t'):], 16)
return (caps & (1 << CAP_NET_ADMIN)) != 0
def capsh_am_in_net_admin():
net_admin_command = 'capsh --print | grep "Current:" | ' \
'cut -d" " -f3 | grep -q cap_net_admin'
return subprocess.call(net_admin_command, shell=True)
if __name__ == '__main__':
sys.exit(am_i_net_admin())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment