Last active
March 2, 2018 11:26
-
-
Save celebdor/ada01aef3f1f58942b1694ace9c9ece5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # 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