Skip to content

Instantly share code, notes, and snippets.

@seanavery
Created May 23, 2020 05:52
Show Gist options
  • Save seanavery/660f963aaa714b4a2f1b26aa9f178d5f to your computer and use it in GitHub Desktop.
Save seanavery/660f963aaa714b4a2f1b26aa9f178d5f to your computer and use it in GitHub Desktop.
RTSP Scanner
import subprocess
# grab subnet address
ps = subprocess.Popen('ifconfig', stdout=subprocess.PIPE, shell=True)
output = subprocess.check_output(('grep', 'inet'), stdin=ps.stdout)
ps.wait()
elements = output.decode('utf8').split()
broadcast_ip = elements[elements.index('broadcast') + 1]
print('broadcast_ip: {}'.format(broadcast_ip))
subnet = broadcast_ip[:-4]
# find devices in subnet
print('checking for devices in subnet')
devices = []
for i in range(256):
res = subprocess.Popen('ping -W 1 -oc 1 192.168.86.{} > /dev/null'.format(i), stdout=subprocess.PIPE, shell=True)
output, err = res.communicate()
rc = res.returncode
if rc == 0:
devices.append('192.168.86.{}'.format(i))
print('found device: 192.168.86.{}'.format(i))
# check if common rtsp ports are open
# !!! only checks for tcp transport
print('checking for rtsp endpoints on devices')
rtsp_ports = ['554', '555', '5554', '5555', '1025']
for device in devices:
for port in rtsp_ports:
cmd = 'nc -vz -w 1 -G 1'
res = subprocess.Popen('nc -vz -w 1 -G 1 {0} {1}'.format(device, port), shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
output, err = res.communicate()
rc = res.returncode
if rc == 0:
print('found rtsp endpoint: {0}:{1}'.format(device, port))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment