Uploaded Test files

This commit is contained in:
Batuhan Berk Başoğlu 2020-11-12 11:05:57 -05:00
parent f584ad9d97
commit 2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions

View file

@ -0,0 +1,105 @@
import win32api
import win32wnet
import sys
from winnetwk import *
import os
possible_shares = []
def _doDumpHandle(handle, level = 0):
indent = " " * level
while 1:
items = win32wnet.WNetEnumResource(handle, 0)
if len(items)==0:
break
for item in items:
try:
if item.dwDisplayType == RESOURCEDISPLAYTYPE_SHARE:
print(indent + "Have share with name:", item.lpRemoteName)
possible_shares.append(item)
elif item.dwDisplayType == RESOURCEDISPLAYTYPE_GENERIC:
print(indent + "Have generic resource with name:", item.lpRemoteName)
else:
# Try generic!
print(indent + "Enumerating " + item.lpRemoteName, end=' ')
k = win32wnet.WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY,0,item)
print()
_doDumpHandle(k, level + 1)
win32wnet.WNetCloseEnum(k) # could do k.Close(), but this is a good test!
except win32wnet.error as details:
print(indent + "Couldn't enumerate this resource: " + details.strerror)
def TestOpenEnum():
print("Enumerating all resources on the network - this may take some time...")
handle = win32wnet.WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,0,None)
try:
_doDumpHandle(handle)
finally:
handle.Close()
print("Finished dumping all resources.")
def findUnusedDriveLetter():
existing = [x[0].lower() for x in win32api.GetLogicalDriveStrings().split('\0') if x]
handle = win32wnet.WNetOpenEnum(RESOURCE_REMEMBERED,RESOURCETYPE_DISK,0,None)
try:
while 1:
items = win32wnet.WNetEnumResource(handle, 0)
if len(items)==0:
break
xtra = [i.lpLocalName[0].lower() for i in items if i.lpLocalName]
existing.extend(xtra)
finally:
handle.Close()
for maybe in 'defghijklmnopqrstuvwxyz':
if maybe not in existing:
return maybe
raise RuntimeError("All drive mappings are taken?")
def TestConnection():
if len(possible_shares)==0:
print("Couldn't find any potential shares to connect to")
return
localName = findUnusedDriveLetter() + ':'
for share in possible_shares:
print("Attempting connection of", localName, "to", share.lpRemoteName)
try:
win32wnet.WNetAddConnection2(share.dwType, localName, share.lpRemoteName)
except win32wnet.error as details:
print("Couldn't connect: " + details.strerror)
continue
# Have a connection.
try:
fname = os.path.join(localName + "\\", os.listdir(localName + "\\")[0])
try:
print("Universal name of '%s' is '%s'" % (fname, win32wnet.WNetGetUniversalName(fname)))
except win32wnet.error as details:
print("Couldn't get universal name of '%s': %s" % (fname, details.strerror))
print("User name for this connection is", win32wnet.WNetGetUser(localName))
finally:
win32wnet.WNetCancelConnection2(localName, 0, 0)
# and do it again, but this time by using the more modern
# NETRESOURCE way.
nr = win32wnet.NETRESOURCE()
nr.dwType = share.dwType
nr.lpLocalName = localName
nr.lpRemoteName = share.lpRemoteName
win32wnet.WNetAddConnection2(nr)
win32wnet.WNetCancelConnection2(localName, 0, 0)
# and one more time using WNetAddConnection3
win32wnet.WNetAddConnection3(0, nr)
win32wnet.WNetCancelConnection2(localName, 0, 0)
# Only do the first share that succeeds.
break
def TestGetUser():
u = win32wnet.WNetGetUser()
print("Current global user is", repr(u))
if u != win32wnet.WNetGetUser(None):
raise RuntimeError("Default value didnt seem to work!")
TestGetUser()
TestOpenEnum()
TestConnection()

View file

@ -0,0 +1,98 @@
# Generated by h2py from d:\mssdk\include\winnetwk.h
WNNC_NET_MSNET = 0x00010000
WNNC_NET_LANMAN = 0x00020000
WNNC_NET_NETWARE = 0x00030000
WNNC_NET_VINES = 0x00040000
WNNC_NET_10NET = 0x00050000
WNNC_NET_LOCUS = 0x00060000
WNNC_NET_SUN_PC_NFS = 0x00070000
WNNC_NET_LANSTEP = 0x00080000
WNNC_NET_9TILES = 0x00090000
WNNC_NET_LANTASTIC = 0x000A0000
WNNC_NET_AS400 = 0x000B0000
WNNC_NET_FTP_NFS = 0x000C0000
WNNC_NET_PATHWORKS = 0x000D0000
WNNC_NET_LIFENET = 0x000E0000
WNNC_NET_POWERLAN = 0x000F0000
WNNC_NET_BWNFS = 0x00100000
WNNC_NET_COGENT = 0x00110000
WNNC_NET_FARALLON = 0x00120000
WNNC_NET_APPLETALK = 0x00130000
WNNC_NET_INTERGRAPH = 0x00140000
WNNC_NET_SYMFONET = 0x00150000
WNNC_NET_CLEARCASE = 0x00160000
WNNC_NET_FRONTIER = 0x00170000
WNNC_NET_BMC = 0x00180000
WNNC_NET_DCE = 0x00190000
WNNC_NET_DECORB = 0x00200000
WNNC_NET_PROTSTOR = 0x00210000
WNNC_NET_FJ_REDIR = 0x00220000
WNNC_NET_DISTINCT = 0x00230000
WNNC_NET_TWINS = 0x00240000
WNNC_NET_RDR2SAMPLE = 0x00250000
RESOURCE_CONNECTED = 0x00000001
RESOURCE_GLOBALNET = 0x00000002
RESOURCE_REMEMBERED = 0x00000003
RESOURCE_RECENT = 0x00000004
RESOURCE_CONTEXT = 0x00000005
RESOURCETYPE_ANY = 0x00000000
RESOURCETYPE_DISK = 0x00000001
RESOURCETYPE_PRINT = 0x00000002
RESOURCETYPE_RESERVED = 0x00000008
RESOURCETYPE_UNKNOWN = 0xFFFFFFFF
RESOURCEUSAGE_CONNECTABLE = 0x00000001
RESOURCEUSAGE_CONTAINER = 0x00000002
RESOURCEUSAGE_NOLOCALDEVICE = 0x00000004
RESOURCEUSAGE_SIBLING = 0x00000008
RESOURCEUSAGE_ATTACHED = 0x00000010
RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED)
RESOURCEUSAGE_RESERVED = 0x80000000
RESOURCEDISPLAYTYPE_GENERIC = 0x00000000
RESOURCEDISPLAYTYPE_DOMAIN = 0x00000001
RESOURCEDISPLAYTYPE_SERVER = 0x00000002
RESOURCEDISPLAYTYPE_SHARE = 0x00000003
RESOURCEDISPLAYTYPE_FILE = 0x00000004
RESOURCEDISPLAYTYPE_GROUP = 0x00000005
RESOURCEDISPLAYTYPE_NETWORK = 0x00000006
RESOURCEDISPLAYTYPE_ROOT = 0x00000007
RESOURCEDISPLAYTYPE_SHAREADMIN = 0x00000008
RESOURCEDISPLAYTYPE_DIRECTORY = 0x00000009
RESOURCEDISPLAYTYPE_TREE = 0x0000000A
RESOURCEDISPLAYTYPE_NDSCONTAINER = 0x0000000B
NETPROPERTY_PERSISTENT = 1
CONNECT_UPDATE_PROFILE = 0x00000001
CONNECT_UPDATE_RECENT = 0x00000002
CONNECT_TEMPORARY = 0x00000004
CONNECT_INTERACTIVE = 0x00000008
CONNECT_PROMPT = 0x00000010
CONNECT_NEED_DRIVE = 0x00000020
CONNECT_REFCOUNT = 0x00000040
CONNECT_REDIRECT = 0x00000080
CONNECT_LOCALDRIVE = 0x00000100
CONNECT_CURRENT_MEDIA = 0x00000200
CONNECT_DEFERRED = 0x00000400
CONNECT_RESERVED = 0xFF000000
CONNDLG_RO_PATH = 0x00000001
CONNDLG_CONN_POINT = 0x00000002
CONNDLG_USE_MRU = 0x00000004
CONNDLG_HIDE_BOX = 0x00000008
CONNDLG_PERSIST = 0x00000010
CONNDLG_NOT_PERSIST = 0x00000020
DISC_UPDATE_PROFILE = 0x00000001
DISC_NO_FORCE = 0x00000040
UNIVERSAL_NAME_INFO_LEVEL = 0x00000001
REMOTE_NAME_INFO_LEVEL = 0x00000002
WNFMT_MULTILINE = 0x01
WNFMT_ABBREVIATED = 0x02
WNFMT_INENUM = 0x10
WNFMT_CONNECTION = 0x20
NETINFO_DLL16 = 0x00000001
NETINFO_DISKRED = 0x00000004
NETINFO_PRINTERRED = 0x00000008
RP_LOGON = 0x01
RP_INIFILE = 0x02
PP_DISPLAYERRORS = 0x01
WNCON_FORNETCARD = 0x00000001
WNCON_NOTROUTED = 0x00000002
WNCON_SLOWLINK = 0x00000004
WNCON_DYNAMIC = 0x00000008