{"action":"created","issue":{"url":"https://api.github.com/repos/ronf/asyncssh/issues/16","labels_url":"https://api.github.com/repos/ronf/asyncssh/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/ronf/asyncssh/issues/16/comments","events_url":"https://api.github.com/repos/ronf/asyncssh/issues/16/events","html_url":"https://github.com/ronf/asyncssh/issues/16","id":81975985,"number":16,"title":"Docs for SSHClientConnection.get_extra_info() need a little elaboration","user":{"login":"nchammas","id":1039369,"avatar_url":"https://avatars.githubusercontent.com/u/1039369?v=3","gravatar_id":"","url":"https://api.github.com/users/nchammas","html_url":"https://github.com/nchammas","followers_url":"https://api.github.com/users/nchammas/followers","following_url":"https://api.github.com/users/nchammas/following{/other_user}","gists_url":"https://api.github.com/users/nchammas/gists{/gist_id}","starred_url":"https://api.github.com/users/nchammas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nchammas/subscriptions","organizations_url":"https://api.github.com/users/nchammas/orgs","repos_url":"https://api.github.com/users/nchammas/repos","events_url":"https://api.github.com/users/nchammas/events{/privacy}","received_events_url":"https://api.github.com/users/nchammas/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-28T15:13:37Z","updated_at":"2015-05-29T02:59:11Z","closed_at":null,"body":"I have an SSH client connection that I reuse and pass around to various methods so as to avoid having to recreate the connection over and over.\r\n\r\nSometimes, I want those methods to print some informational messages about what they are doing and to which server, so I need a way to extract the server IP address from an existing SSH client.\r\n\r\nI eventually figured out that the way to do this is as follows:\r\n\r\n```python\r\nwith (yield from asyncssh.connect('localhost')) as conn:\r\n    (host, port, _, _) = conn.get_extra_info('peername')\r\n```\r\n\r\nThis is not clear from [the docs for `get_extra_info()`](http://asyncssh.readthedocs.org/en/stable/api.html#asyncssh.SSHClientConnection.get_extra_info). It would be helpful if they linked to the appropriate Python docs (if any) that show all the supported values for the `name` input parameter.\r\n\r\nAn additional but separate suggestion would be to perhaps allow users to call `get_extra_info()` without any arguments and get back a dictionary of all the available information. That would help with discovery of the available properties."},"comment":{"url":"https://api.github.com/repos/ronf/asyncssh/issues/comments/106666655","html_url":"https://github.com/ronf/asyncssh/issues/16#issuecomment-106666655","issue_url":"https://api.github.com/repos/ronf/asyncssh/issues/16","id":106666655,"user":{"login":"ronf","id":1901085,"avatar_url":"https://avatars.githubusercontent.com/u/1901085?v=3","gravatar_id":"","url":"https://api.github.com/users/ronf","html_url":"https://github.com/ronf","followers_url":"https://api.github.com/users/ronf/followers","following_url":"https://api.github.com/users/ronf/following{/other_user}","gists_url":"https://api.github.com/users/ronf/gists{/gist_id}","starred_url":"https://api.github.com/users/ronf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ronf/subscriptions","organizations_url":"https://api.github.com/users/ronf/orgs","repos_url":"https://api.github.com/users/ronf/repos","events_url":"https://api.github.com/users/ronf/events{/privacy}","received_events_url":"https://api.github.com/users/ronf/received_events","type":"User","site_admin":false},"created_at":"2015-05-29T02:59:11Z","updated_at":"2015-05-29T02:59:11Z","body":"When I first put together the docs, I didn't have the linking to the main Python docs working, but I managed to fix that recently. Including a link directly to asyncio.BaseTransport's get_extra_info() documentation is a good idea. I'll add that to my list and get it in once I check in some other cleanup I'm in the middle of.\r\n\r\nBy the way, you need to be careful with the 'peername' and 'sockname' keys there. They are only 4-tuples for IPv6. For IPv4, I believe you'll only get back a 2-tuple of host & port. I dealt with this in AsyncSSH by using the following construct:\r\n\r\n```python\r\n    host, port = conn.get_extra_info('peername')[:2]\r\n```\r\n\r\nEven this is potentially dangerous, though, if for some reason the underlying socket is not about to return a peer name. For safety, you should check if peername is None before you unpack it, or provide a default value in the get_extra_info() call which is a 2-tuple to avoid getting an error in the unpack.\r\n\r\nRegarding getting back all of the keys you can query, I don't really know how to do that for the values being returned by the base transport. While the data is stored internally in the transport as a dictionary, there's no public API to access that directly."}}