1

How can i manage to get the IP or path like \11.1.1.100\projects of a connected network share with a drive letter. I only have the drive letter and want to get the IP of the Share with python. Many Thanks... Sashmo

jsbueno
  • 99,910
  • 10
  • 151
  • 209
Sashmo
  • 11
  • 2

1 Answers1

2

I don't know the python equivalent, but WNetGetConnection will give you the UNC path mapped to the drive letter:

wchar_t szName[256];
DWORD chName = 256;
DWORD dwResult = WNetGetConnectionW(L"Z:", szName, &chName);

I'm sure there is a python module that wraps this functionality. From the UNC path you can get the server name, and from that you can lookup its IP address.

Luke
  • 11,211
  • 2
  • 27
  • 38
  • thank you for your answer! Throug this WNetGetConnectionW i came across win32net for python and that did the trick. – Sashmo Jul 16 '10 at 12:02
  • `win32wnet.WNetGetConnection('X:')` – yurisich May 29 '12 at 20:43
  • Use this in combination with [this question/answer](http://stackoverflow.com/questions/827371/is-there-a-way-to-list-all-the-available-drive-letters-in-python) to do some useful stuff with drive mapping/unmapping (my current headache). – yurisich May 29 '12 at 21:04