Python Forum

Full Version: listdir on IP Adress
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hallo Guys,

I need to get content of a windows "networkshare".
It is and will not be added as networkdrive with a letter.

In Windows Explorer I can resolve the content via "\\192.168.5.1"
--> dir1
--> dir2


With Python I am trying
import os
d=os.listdir('\\\\192.168.5.1')
and differnt version of slashes

--> In the best case I get: FileNotFoundError: [WinError 67]


any help
that ip address links to several domains see: https://whois.domaintools.com/192.168.5.1
it seems to connect to none of them, thus your File Not Found error
@Larz60+ it's a private IP in his home network or somewhere else behind a router.

The easy short solution is, to mount your samba share to a drive letter.
Then you can use open(), os.listdir and other operations on file system.

You can't use open or other file system operations like os.listdir on a samba share.
You can access with a client the samba share: https://pypi.org/project/smbprotocol/
For whatever reason, although you can list the contents of the shares, you don't seem to be able to list the shares themselves. On my windows 10 machine:

>>> len(os.listdir('//10.0.0.10'))  # fails to list the shares by IP
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [WinError 67] The network name cannot be found: '//10.0.0.10'

>>> len(os.listdir('//10.0.0.10/USB_Storage'))   # listing contents of a share works fine
84