-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlsof-udp
More file actions
executable file
·31 lines (26 loc) · 837 Bytes
/
Copy pathlsof-udp
File metadata and controls
executable file
·31 lines (26 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
# lsof-listening [-6]: list programs listening on a TCP port (e.g. servers)
# lsof-udp: list programs bound to a UDP port
import sys
import os
import subprocess
import optparse
def program_name():
return os.path.basename(sys.argv[0])
def main(args):
p = program_name()
if p == 'lsof-listening':
op = optparse.OptionParser(option_list = [
optparse.Option('-6', '--ipv6', action='store_true')
])
(options, args) = op.parse_args(args)
cmd = 'sudo lsof -i -nP | grep LISTEN'
if not options.ipv6:
cmd += '| grep -v IPv6'
subprocess.check_call(cmd, shell=1)
elif p == 'lsof-udp':
subprocess.check_call('sudo lsof -i -nP | grep UDP', shell=1)
else:
assert(0)
if __name__ == '__main__':
main(sys.argv[1:])