1

How to get from a python script, running with cmd administrator rights, the hostname or ip from mapped letter? with this post Python 2: Get network share path from drive letter:

import win32wnet
import sys

print(win32wnet.WNetGetUniversalName(sys.argv[1], 1))

This gives me something like this when I run it:

C:\test>python get_unc.py i:\some\path
\\machine\test_share\some\path

This works if I run without administrator privileges, but I need to run with admin rights.

rafael
  • 11
  • 3

1 Answers1

0

You can do this with the stdlib:

import socket

print('Hostname', socket.gethostname())
print('IP', socket.gethostbyname(socket.gethostname()))
Matias Cicero
  • 25,439
  • 13
  • 82
  • 154
  • With this I just get the local machine, I need the mapped drive letter, for example, if i:\some\path is mapped to \\10.200.51.134, then it should return \\10.200.51.134\mypath\some\path – rafael Sep 22 '21 at 00:34