-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.py
143 lines (127 loc) · 4.27 KB
/
map.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
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
136
137
138
139
140
141
142
143
import os, time, argparse, subprocess
from configparser import ConfigParser
#CONFIG
config = ConfigParser()
config.read('config.ini')
J = config.get('shares', 'J')
H = config.get('shares', 'H')
S = config.get('shares', 'S')
W = config.get('shares', 'W')
userString = config.get('login', 'user')
passString = config.get('login', 'pass')
continueH = config.get('run', 'continueH')
continueJ = config.get('run', 'continueJ')
#FUNCTIONS
def getIP():
IP_array = []
ipconfig_array = str(subprocess.check_output('ipconfig')).split('\\r\\n')
for line in ipconfig_array:
if 'IPv4' in line:
IP_array.append(line.split(':')[1])
return IP_array[0].strip()
def showLogo():
print('''
___ ___
| \/ |
_ __ _ _| . . | __ _ _ __
| '_ \| | | | |\/| |/ _` | '_ \
| |_) | |_| | | | | (_| | |_) |
| .__/ \__, \_| |_/\__,_| .__/
| | __/ | | |
|_| |___/ |_|
''')
def getInfo():
print(' Hello, '+str(os.getlogin())+'!')
print(' IP: '+getIP())
print(' user: '+username)
print(' pass: '+password)
def map(drive, server, user, pwd, persistence):
print('RUNNING: '+"net use"+' '+drive+' '+server+' '+'/u:'+user+' '+pwd+' '+'/persistent:'+persistence)
subprocess.run(['net', 'use', drive, server, '/u:'+user, pwd, '/persistent:'+persistence], shell=True, check=True)
time.sleep(3)
def unmap(drive):
subprocess.run(['net', 'use', drive, '/delete'], shell=True, check=True)
time.sleep(3)
def runBat(path):
if os.path.exists(path):
subprocess.run(path, shell=True, check=True)
else:
print('runBat: PATH DOES NOT EXIST')
#VARIABLES
username = userString+getIP().split('.')[3]
password = passString+getIP().split('.')[3]
#ARGPARSE
#Pro Tip: type=str.lower makes cmdline arguments case insensitive
parser = argparse.ArgumentParser()
parser.add_argument('-m', '--map', help='Map A File Share', type=str.lower, choices=['j','h','s','w'])
parser.add_argument('-u', '--unmap', help='Unmap A File Share', type=str.lower, choices=['j','h','s','w'])
parser.add_argument('-r', '--run', help='Runs Server Batch File', type=str.lower, choices=['j','h'])
parser.add_argument('-q', '--quiet', help='Do Not Display Logo', action='store_false')
parser.add_argument('-i', '--info', help='Get Info', action='store_true')
args = parser.parse_args()
#LOGO
if args.quiet:
showLogo()
#INFO
if args.info:
getInfo()
#RUN SERVER BATCH FILE
try:
if args.run == 'h':
run_bat(continueH)
if args.run == 'j':
run_bat(continueJ)
except subprocess.CalledProcessError as err:
print('SUBPROCESS ERROR: '+str(err))
#UNMAP
try:
if args.unmap == 'j':
if os.path.exists('J:'):
unmap('J:')
else:
print('J: Not Found')
if args.unmap == 'h':
if os.path.exists('H:'):
unmap('H:')
else:
print('H: Not Found')
if args.unmap == 's':
if os.path.exists('S:'):
unmap('S:')
else:
print('S: Not Found')
if args.unmap == 'w':
if os.path.exists('W:'):
unmap('W:')
else:
print('W: Not Found')
except subprocess.CalledProcessError as err:
print('SUBPROCESS ERROR: '+str(err))
#MAP
try:
if args.map == 'j':
if not os.path.exists('J:'):
print('Connecting...')
map('J:', J, username, password, 'yes')
else:
print('Drive Already Mapped')
if args.map == 'h':
if not os.path.exists('H:'):
print('Connecting...')
map('H:', H, username, password, 'yes')
else:
print('Drive Already Mapped')
if args.map == 's':
if not os.path.exists('S:'):
print('Connecting...')
map('S:', S, username, password, 'yes')
else:
print('Drive Already Mapped')
if args.map == 'w':
if not os.path.exists('W:'):
print('Connecting...')
map('W:', W, username, password, 'yes')
else:
print('Drive Already Mapped')
except subprocess.CalledProcessError as err:
print('SUBPROCESS ERROR: '+str(err))