Skip to content

Instantly share code, notes, and snippets.

@nihey
Last active April 12, 2016 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nihey/b9bcafd14f52763654d5bc9c7600f6bf to your computer and use it in GitHub Desktop.
Save nihey/b9bcafd14f52763654d5bc9c7600f6bf to your computer and use it in GitHub Desktop.
Expose IP Camera Workaround
# This code is highly experimental, it works for me, but use at your own risk!
import subprocess
import requests
MAILER_URL = ''
LT_PATH = '/home/nihey/.nvm/versions/node/v4.2.3/bin/lt'
BASE_IP = '192.168.99.{}'
base_url = 'http://{}/video.cgi'.format(BASE_IP)
def scan():
for address in xrange(255, 0, -1):
# Trying desperately to find a DCS-* Camera in the network
url = base_url.format(address)
print 'Trying', url
try:
response = requests.get(url, timeout=0.1)
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError):
print 'Timed out, proceeding'
continue
# Just by getting the 401 response in the '/video.cgi' we assume we are
# dealing with a DCS-* Camera So we should localtunnel it
if response.status_code == 401:
# Never stop localtunneling it again
while True:
print 'Camera Found, running localtunnel...'
popen = subprocess.Popen([LT_PATH, '-l', BASE_IP.format(address),
'-p', '80'], stdout=subprocess.PIPE)
while True:
line = popen.stdout.readline()
print line
if line == '':
break
if 'your url is: ' in line:
url = line.replace('your url is: ', '').rstrip('\n')
response = requests.get(MAILER_URL, params={
'url': url + '/video.cgi',
'ip': BASE_IP.format(address),
})
print response.text
break
popen.wait()
# Neve stop looking for a camera, believe in it
scan()
scan()
function doGet(e) {
var emails = 'nihey.takizawa@gmail.com'.split(',');
var subject = 'Camera URL Changed';
var body = 'Camera URL: ' + e.parameter.url + '\n' +
'Located on IP: ' + e.parameter.ip;
emails.forEach(function(email) {
try {
GmailApp.sendEmail(email, subject, body);
} catch(e) {}
});
return ContentService.createTextOutput("OK");
}
[program:camera-exposer]
numprocs=1
command=python /root/expose.py
redirect_stderr=true
stdout_logfile=/var/log/camera-exposer.log
autorestart=true
user=root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment