Get DFS path to network location in Python

I want to get a ping-like response from a Windows network location that has a distributed file system architecture, for example.

path = r'\\path\to\some\shared\folder_x'
delay = ping_func(path)
print delay # return response in milliseconds ?
234

      

Once I have a host computer, I can check the location easily.

I can figure out the hostname for folder_x

by looking at the DFS tab in Windows Explorer, which will look like, for example

\\hostcomputer.server.uk\shared$\folder_x

      

How can I do this programmatically in Python?

+3


source to share


1 answer


Since you are using Windows, always install pywin32

and WMI

to get WMI functionality. And below should help you connect to remote DFS. Can't check it as I don't have Windows or DFS



import wmi

c = wmi.WMI (ip, user="user", password="pwd")

for share in c.Win32_Share (Type=0):
  print share.Caption, share.Path
  for session in share.associators (
    wmi_result_class="Win32_ServerConnection"
  ):
    print "  ", session.UserName, session.ActiveTime

      

+1


source







All Articles