Skip to content
New issue

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

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

Already on GitHub? # to your account

changed _build_url to include ability to parse ipv6 host with bracket… #92

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lawrencellui-dd
Copy link

… notation

@coveralls
Copy link

Coverage Status

Coverage remained the same at 57.105% when pulling 39900e2 on lawrencellui-dd:develop into 41aa058 on diyan:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 57.105% when pulling e22f94e on lawrencellui-dd:develop into 41aa058 on diyan:master.

@nitzmahone nitzmahone mentioned this pull request Apr 4, 2017
Copy link

@stuartgh stuartgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@badcure @nitzmahone

Is there a chance of getting this in? or something that needs to be changed? I am willing to make them to get this in.

>>> import re
>>> import winrm
>>> class v6Session(winrm.Session):
...     @staticmethod
...     def _build_url(target, transport):
...         match = re.match(
...             '(?i)^((?P<scheme>http[s]?)://)?(?P<host>[0-9a-z-_.]+|\[[0-9a-f:]+])(:(?P<port>\d+))?(?P<path>(/)?(wsman)?)?', target)
...         groups = match.groupdict()
...         if groups['scheme'] is None:
...             groups['scheme'] = 'https' if transport == 'ssl' else 'http'
...         if groups['port'] is None:
...             groups['port'] = 5986 if transport == 'ssl' else 5985
...         if not groups['path']:
...             groups['path'] = 'wsman'
...         return '{scheme}://{host}:{port}/{path}'.format(**groups)
... 
>>> c = winrm.Session('[****]', auth=('Administrator','****'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/winrm/__init__.py", line 31, in __init__
    self.url = self._build_url(target, kwargs.get('transport', 'plaintext'))
  File "/usr/lib/python2.7/site-packages/winrm/__init__.py", line 106, in _build_url
    scheme = match.group('scheme')
AttributeError: 'NoneType' object has no attribute 'group'
>>> c = v6Session('[****]', auth=('Administrator','****'))
>>> c.run_cmd('ver')
<Response code 0, out "
Microsoft Windows ", err "">

@@ -94,7 +94,7 @@ def strip_namespace(self, xml):
@staticmethod
def _build_url(target, transport):
match = re.match(
'(?i)^((?P<scheme>http[s]?)://)?(?P<host>[0-9a-z-_.]+)(:(?P<port>\d+))?(?P<path>(/)?(wsman)?)?', target) # NOQA
'(?i)^((?P<scheme>http[s]?)://)?(?P<host>\[[0-9A-Fa-f:]+]|[0-9a-z-_.]+)(:(?P<port>\d+))?(?P<path>(/)?(wsman)?)?', target) # NOQA

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the A-F is not needed as this is already case insensitive.

@reillysiemens
Copy link

@badcure @nitzmahone: Is there anything more that needs to be done to incorporate this work?

@pnfox
Copy link

pnfox commented Aug 23, 2023

These changes do allow me to run winrm with ipv6, any chance of getting this merged?

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

Successfully merging this pull request may close these issues.

5 participants