Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial IPv6 support? #180

Closed
frafra opened this issue Feb 20, 2021 · 4 comments · Fixed by #183
Closed

Partial IPv6 support? #180

frafra opened this issue Feb 20, 2021 · 4 comments · Fixed by #183

Comments

@frafra
Copy link
Contributor

frafra commented Feb 20, 2021

Is IPv6 supported?

    self.sock.connect(( ip, port ))
socket.gaierror: [Errno -9] Address family for hostname not supported

Couldn't sock_family be detected automatically? Python 3 has the ipaddress module.

When I set sock_family to AF_INET6 I get another error:

  File "/home/frafra/.cache/pypoetry/virtualenvs/viltkamera-manager-QhDdi_a7-py3.8/lib/python3.8/site-packages/smb/SMBConnection.py", line 122, in connect
    self._pollForNetBIOSPacket(timeout)
  File "/home/frafra/.cache/pypoetry/virtualenvs/viltkamera-manager-QhDdi_a7-py3.8/lib/python3.8/site-packages/smb/SMBConnection.py", line 637, in _pollForNetBIOSPacket
    self.feedData(data)
  File "/home/frafra/.cache/pypoetry/virtualenvs/viltkamera-manager-QhDdi_a7-py3.8/lib/python3.8/site-packages/nmb/base.py", line 49, in feedData
    length = self.data_nmb.decode(self.data_buf, offset)
  File "/home/frafra/.cache/pypoetry/virtualenvs/viltkamera-manager-QhDdi_a7-py3.8/lib/python3.8/site-packages/nmb/nmb_structs.py", line 60, in decode
    raise NMBError("Invalid protocol header for Direct TCP session message")
nmb.nmb_structs.NMBError: Invalid protocol header for Direct TCP session message

is_direct_tcp is set to True as it looks to me that NetBIOS does not work in IPv6. Setting it to False produces a timeout.

smbclient works just fine instead.

@frafra frafra changed the title No IPv6 support Partial IPv6 support? Feb 20, 2021
@miketeo
Copy link
Owner

miketeo commented Feb 20, 2021

When you set is_direct_tcp=True, did you connect to port 445 ?

@frafra
Copy link
Contributor Author

frafra commented Mar 4, 2021

@miketeo You are right, thank you, the port was wrong indeed. I cannot try with IPv6 right now, but I would guess that will solve the issue.

@frafra
Copy link
Contributor Author

frafra commented Mar 23, 2021

It works if I use the IP address instead of the hostname, which has been specified in /etc/hosts.

@frafra frafra closed this as completed Mar 23, 2021
@frafra
Copy link
Contributor Author

frafra commented May 28, 2021

I can confirm there is an issue with IPv6. IPv4 is assumed to be the default, so if I try to connect to hosts over IPv6, I need to specify that.

def connect(self, ip, port = 139, sock_family = socket.AF_INET, timeout = 60):

self.sock = socket.socket(sock_family)
self.sock.settimeout(timeout)
self.sock.connect(( ip, port ))

Wouldn't it better to use socker.create_server with support both IPv4 and IPv6?

self.sock = socket.create_connection(( ip, port ), timeout)

Reference: https://docs.python.org/3/library/socket.html#socket.create_connection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants