-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathintcam.py
More file actions
135 lines (115 loc) · 4.69 KB
/
Copy pathintcam.py
File metadata and controls
135 lines (115 loc) · 4.69 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python3
import subprocess
import argparse
import json
import os
import requests
from requests.exceptions import RequestException
# Configuration file path
CONFIG_FILE = 'config.json'
IP_SERVICE_URL = 'https://api.ipify.org?format=json'
def get_public_ip():
try:
response = requests.get(IP_SERVICE_URL)
response.raise_for_status()
return response.json()['ip']
except RequestException as e:
print(f"Error getting public IP: {e}")
return None
def load_config():
if not os.path.exists(CONFIG_FILE):
return {}
with open(CONFIG_FILE, 'r') as file:
try:
config = json.load(file)
except json.JSONDecodeError as e:
print(f"Error decoding config file: {e}")
return {}
return config
def save_config(config):
try:
with open(CONFIG_FILE, 'w') as file:
json.dump(config, file, indent=4)
except IOError as e:
print(f"Error saving config file: {e}")
def take_photo(ip, port):
print(f"Taking photo from camera at {ip}:{port}")
try:
result = subprocess.run(
["ssh", f"user@{ip}", "fswebcam -r 1280x720 --jpeg 85 -D 1 /tmp/webcam.jpg"],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
with open("camera_output.txt", "w") as f:
f.write(result.stdout)
print(f"Photo taken successfully. Output saved to 'camera_output.txt'.")
except subprocess.CalledProcessError as e:
with open("camera_error.txt", "w") as f:
f.write(e.stderr)
print(f"Error taking photo: {e}")
def take_screen_photo(ip, port):
print(f"Taking screen photo from {ip}:{port}")
try:
result = subprocess.run(
["ssh", f"user@{ip}", "scrot /tmp/screenshot.png"],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
with open("screen_output.txt", "w") as f:
f.write(result.stdout)
print(f"Screen photo taken successfully. Output saved to 'screen_output.txt'.")
except subprocess.CalledProcessError as e:
with open("screen_error.txt", "w") as f:
f.write(e.stderr)
print(f"Error taking screen photo: {e}")
def main():
print("""
___.-------.___
_.-' ___.--;--.___ `-._
.-' _.-' / .+. \ `-._ `-.
.' .-' |-|-o-|-| `-. `.
(_ <O__ \ `+' / __O> _)
`--._``-..__`._|_.'__..-''_.--'
``--._________.--''
██╗███╗ ██╗████████╗ ██████╗ █████╗ ███╗ ███ ╗
██║████╗ ██║╚══██╔══╝██╔════╝██╔══██╗████ ╗ ████║
██║██╔██╗ ██║ ██║ ██║ ███████║██╔████╔██║
██║██║╚██╗██║ ██║ ██║ ██╔══██║██║╚██╔╝██║
██║██║ ╚████║ ██║ ╚██████╗██║ ██║██║ ╚═╝ ██║
╚═╝╚═╝ ╚═══╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝
""")
parser = argparse.ArgumentParser(description='intweb')
parser.add_argument('-ip', '--ipv4', type=str, help='Specify the IP address')
parser.add_argument('-p', '--port', type=int, required=True, help='Specify the port number')
parser.add_argument('-c', '--camera-photo', action='store_true', help='Take a photo from the camera')
parser.add_argument('-s', '--screen-photo', action='store_true', help='Take a screen photo')
parser.add_argument('--uip', '--use-public-ip', action='store_true', help='Use the public IP address')
args = parser.parse_args()
if args.uip:
public_ip = get_public_ip()
if public_ip:
args.ipv4 = public_ip
else:
print("Could not retrieve public IP address.")
return
config = load_config()
if args.ipv4:
config['ipv4'] = args.ipv4
save_config(config)
ip = config.get('ipv4')
port = args.port
if not ip:
print("IP address must be specified either via command line or in the configuration file.")
return
if args.camera_photo:
take_photo(ip, port)
elif args.screen_photo:
take_screen_photo(ip, port)
else:
print("No action specified. Use -c to take a camera photo or -s to take a screen photo.")
if __name__ == '__main__':
main()