-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZukenUserList.py
53 lines (48 loc) · 1.88 KB
/
ZukenUserList.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
import pathlib,re,subprocess,pandas
log_file=pathlib.WindowsPath(r'\\uranus\license\debug.log')
if log_file.exists() == False:
raise FileExistsError(f"{log_file} is not found")
class Users():
def __init__(self):
self.UserList=[]
def add_user(self,match):
self.UserList.append([match.group("kind"),match.group("user"),match.group("computer")])
def remove_user(self,match):
self.UserList.remove([match.group("kind"),match.group("user"),match.group("computer")])
def UserList(log:pathlib.Path):
Users_data=Users()
with open(log) as log_f:
log_lines = log_f.readlines()
pattern=r'\d*:\d*:\d* \(zuken\) (?P<in_out>.*?): "(?P<kind>.*?)" (?P<user>.*?)@(?P<computer>.*?) '
for line in log_lines:
if line == log_lines[-5]:
print()
match=re.search(pattern,line)
if match is not None:
if match.group("in_out") == "OUT":
Users_data.add_user(match)
elif match.group("in_out") == "IN":
Users_data.remove_user(match)
return Users_data.UserList
def get_user_info(user):
cmd=f'net user {user} /domain'
result=subprocess.run(cmd, capture_output=True, text=True)
#参考:https://atmarkit.itmedia.co.jp/ait/articles/0609/02/news014.html
result_line = result.stdout.splitlines()
for line in result_line:
list_a=re.split(' {2,}',line)
try:
if list_a[0] == 'フル ネーム':
return str(list_a[1]).replace('\u3000','')
except:
next
def get() -> pandas.DataFrame:
User_data=UserList(log_file)
for i in range(len(User_data)):
User_data[i].append(get_user_info(User_data[i][1]))
User_data_df=pandas.DataFrame(data=User_data,columns=["kind","ID","PC-ID","FullName"])
print(User_data_df)
return User_data_df
if __name__=="__main__":
get()
input("finish")