miketeo/pysmb

Timeout error while I can login to the SMB server within the OS

Closed this issue · 7 comments

I am trying to list the shared devices of a SMB server. While I can connect to that server from my Mac OS but the same time when I try to connect to that server through SMBConnection I get time out error. I am sure that the server is up and running.

from smb.SMBConnection import SMBConnection 
smb_conn = SMBConnection(username='Guest',password="",my_name='name',remote_name='servernme',sign_options= SMBConnection.SIGN_NEVER)
ip = 'x.x.x.x'
is_connected = smb_conn.connect(ip,timeout=120)
if is_connected:
print("[+] %s connected"%ip)

Why am I getting time out error despite can connect to the server within my OS?

Port 139 could be blocked by firewall.

Perhaps, you can try connecting on port 445
smb_conn.connect(ip, port=445, timeout=120)

One simple question how should I know which port should I connect to?
Should try connect to that server twice one with port 139 and if failed with port 445?
This question becomes more interesting when I notice that my Desktop environment smb tool knows that without asking me.
Another problem I face is there are some servers that I can not get their hostname even with socket.gethostbyaddr(). So is it absolutely impossible to connect to the servers that I don't know their exact hostname?

Port 139 and 445 are well-known ports for SMB and registered under IANA.

Not all developers would want the retry feature for their purposes. It can be coded easily if their apps require such a purpose. pysmb's target users are developers while the desktop tool you mentioned is for end-users.

On LANs, SMB uses NetBIOS lookup to learn the IP address of the server.

Is it possible to connect to a SMB server without knowing its exact server name?

Not that I know of. All the SMB services that I have tested with require you to use the correct server name.

@PakanAngel
if you have a DNS configured you also could use gethostbyaddr this i am using to get name without netbios

Thanks for the help