-
Notifications
You must be signed in to change notification settings - Fork 2
/
file.py
85 lines (70 loc) · 2.64 KB
/
file.py
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
#!/usr/bin/env python3
from sys import argv
import atexit
import os
script, filename = argv
if not os.path.exists(".ssh"):
os.makedirs(".ssh")
print ("ssh folder created")
print ("\n")
if os.path.exists('.ssh/' + filename):
print ("Config File exists in .ssh/")
print ("Now We Editing the same Config file")
print ("\n")
filename = ".ssh/config"
def exit_handler():
print ('Information Saved')
if os.path.exists:
config = open(filename, 'a')
print ("Creating The ssh config File")
print ("\n")
else:
config = open(filename, 'w')
print (config)
if input("Do you want to create ssh key (y). Skip with Enter: "):
os.system("ssh-keygen -t rsa")
print ("\n")
scan1 = input("Scan Your network for open ssh:")
os.system("nmap -v " + scan1 + "/24" + "| grep " + " 'ssh'")
print ("\n")
scan2 = input("Scan Your network for IP Addresses: ")
os.system("nmap -v " + scan2 + "/24" + "| grep " + " 'port 22'")
print ("\n")
try:
while True:
first = input("Please Enter Machine Name: ")
zero = input("This for the root user:")
second = input("Please Enter The Hostname Of the Machine Or IP Address: ")
third = input("Please Enter The Port Number. Skip with Enter: ")
fourth = input("Please Enter The User: " )
fifth = input("Copy the ssh id to the machine. Do you want to continue (y) ")
sixth = input("Copy the ssh id to root. Do you want to continue (y):")
if first:
config.write("Host " + first)
config.write("\n")
if second:
config.write("Hostname " + second)
config.write("\n")
if third:
config.write("Port " + third)
config.write("\n")
if fourth:
config.write("User " + fourth)
config.write("\n")
config.write("\n")
if zero:
config.write("\n")
config.write("Host " + zero + "\n" + "Hostname " + second + "\n" + third + "\n" + "User " + "root" + "\n")
config.write("\n")
if fifth:
os.system("ssh-copy-id " + fourth + "@" + second)
if sixth:
os.system("ssh -t " + fourth + "@" + second + " " + " " " 'sudo cp --parents .ssh/authorized_keys /root/' ")
print ("Finished and starting with the new machine")
print ("\n")
if first != fourth:
config.write("\n")
config.write("\n")
except KeyboardInterrupt:
config.close()
atexit.register(exit_handler)