Advertisement
Mark2020H

Revised Python Script to print external IP On Image For WEBCAM SECURITYTY

Feb 1st, 2022
1,839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 0 0
  1. #Revised code for PYTHON Security  webcam  using WEB Page MD HARRINGTON
  2.  
  3.  
  4. import cv2
  5. import ftplib
  6. import sched, time
  7. import geocoder
  8. from requests import get
  9.  
  10.  
  11. from datetime import datetime
  12.  
  13.  
  14.  
  15. # this is the function that will be called on starting thread
  16. def saveImage(s):
  17.     print(s)
  18.    
  19.     ret,frame = vid.read()
  20.     vid.release() #releasing camera immediately after capturing picture
  21.     now = datetime.now() # current date and time
  22.     date_time = now.strftime("%d/%m/%Y, %H:%M:%S") +"\n"
  23.    
  24.    
  25.     ip = get('https://api.ipify.org').content.decode('utf8')
  26.     str1 = ('{}'.format(ip))
  27.    
  28.     # concat strings
  29.     text = str1 + '\n' + date_time
  30.    
  31.     y_start = 40
  32.  
  33.     y_increment = 50
  34.  
  35.     for i, line in enumerate(text.split('\n')):
  36.         y = y_start + i*y_increment
  37.         cv2.putText(frame ,
  38.                     line,
  39.                     org=(10, y),
  40.                     fontFace=cv2.FONT_HERSHEY_SCRIPT_COMPLEX, fontScale=1, color=(255,255,255),
  41.                     thickness=1)
  42.  
  43.  
  44.  
  45.  
  46.    
  47.  
  48.     cv2.imwrite('img.jpg', frame)
  49.  
  50.  
  51.        
  52.  
  53. def uploadtoFTPServer():
  54.     # Fill Required Information
  55.     HOSTNAME = "x12.x10hosting.com"
  56.     USERNAME = "YOUR LOGIN"
  57.     PASSWORD = "YOUR FTP PASSWORD "
  58.  
  59.     filename = "img.jpg"
  60.     ftp_server = ftplib.FTP(HOSTNAME, USERNAME, PASSWORD)
  61.  
  62.     # force UTF-8 encoding
  63.     ftp_server.encoding = "utf-8"
  64.     ftp_server.cwd("/domains/eliteprojects.x10host.com/public_html")
  65.     with open(filename, "rb") as file:
  66.        # data = []
  67.         #ftp_server.dir(data.append)
  68.  
  69.         #for line in data:
  70.  
  71.             #print ( "-", line)
  72.  
  73.  
  74.         # Command for Uploading the file "STOR filename"
  75.         ftp_server.storbinary(f"STOR {filename}", file)
  76.         time.sleep(2)
  77.         ftp_server.quit()
  78.  
  79.  
  80.  # main execution starts here
  81.  
  82.  
  83.  
  84.  
  85. while(True):
  86.     vid = cv2.VideoCapture(0)
  87.     vid.set(3, 640)
  88.     vid.set(4, 480)
  89.     time_now = time.time()
  90.     saveImage(time_now)
  91.     time.sleep(1)
  92.    
  93.     uploadtoFTPServer()
  94.    
  95.    
  96.  
  97.    
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement