开发者

Python Script to List Local Users using Win32net

开发者 https://www.devze.com 2023-04-07 12:57 出处:网络
I\'m using this script on a LAN to get each of the machines to list out their local administrators and users. There has been a security breach in our network where a couple students have created local

I'm using this script on a LAN to get each of the machines to list out their local administrators and users. There has been a security breach in our network where a couple students have created local admins off directory, and we need to find out where. The list it imports just has the IP addresses of the entire network listed in it like

192.168.1.1
192.168.1.2
192.168.1.3

When only one IP is in the list, the script works and reports back with all local admins/users on the machine, but when there is two or more, the script errors out with the error: (1722, 'Net开发者_开发知识库GroupGetUsers', 'The RPC server is unavailable.') When either of them is put in by themselves, they list fine so its not a matter of the IP's not working.

import win32net

def GetUsers( IP ):
 print IP,
 print win32net.NetGroupGetUsers(IP,'none',0), 
return

F = open("C:\Users\JOHNDOE\Desktop\IP_List.txt")

for CurrentIP in F:
 GetUsers(CurrentIP),

 F.close()

I am pretty new to python programming so I admit that I may have made a stupid mistake in writing this. From what I have seen, this can be done somewhat easier in VBscript, but our supervisor told us that it had to be done in python. Any help would be much appreciated.


As you have it here, the file is closed after the first call to GetUsers() - you should dedent the F.close().

My guess is that the real problem is extraneous newline characters on the line, so try:

for CurrentIP in F.readlines():
    GetUsers( CurrentIP.strip() );

F.close()

As a matter of Python style, four-space indentation is far, far preferable to one-space, and function definitions and local variable names should start with lowercase characters (e.g. currentIp, getUsers()).

0

精彩评论

暂无评论...
验证码 换一张
取 消