Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain the DFS path of a network location in Python

I want to obtain a ping-like response from a Windows network location that has a Distributed File System architecture e.g.

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

Once I have host computer I can easily ping the location.

I can determine the host name for folder_x by looking at the DFS tab in the windows explorer which will look like e.g.

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

How can I do this programmatically in Python?

like image 832
Alexander McFarlane Avatar asked Sep 13 '25 20:09

Alexander McFarlane


1 Answers

Since you are using Windows, your always install pywin32 and WMI to get the WMI functions. And below should help you connect to remote DFS. Can't test 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
like image 178
Tarun Lalwani Avatar answered Sep 17 '25 20:09

Tarun Lalwani