Python socket.getnameinfo() Examples
The following are 30
code examples of socket.getnameinfo().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
socket
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: resolver.py From arissploit with GNU General Public License v3.0 | 6 votes |
def override_system_resolver(resolver=None): """Override the system resolver routines in the socket module with versions which use dnspython's resolver. This can be useful in testing situations where you want to control the resolution behavior of python code without having to change the system's resolver settings (e.g. /etc/resolv.conf). The resolver to use may be specified; if it's not, the default resolver will be used. @param resolver: the resolver to use @type resolver: dns.resolver.Resolver object or None """ if resolver is None: resolver = get_default_resolver() global _resolver _resolver = resolver socket.getaddrinfo = _getaddrinfo socket.getnameinfo = _getnameinfo socket.getfqdn = _getfqdn socket.gethostbyname = _gethostbyname socket.gethostbyname_ex = _gethostbyname_ex socket.gethostbyaddr = _gethostbyaddr
Example #2
Source File: test_tcp.py From learn_python3_spider with MIT License | 6 votes |
def test_serverGetHostOnIPv6ScopeID(self): """ When a connection is accepted over IPv6, the server L{ITransport.getHost} method returns an L{IPv6Address} giving the address on which the server accepted the connection, including the scope identifier. """ interface = getLinkLocalIPv6Address() client = createTestSocket(self, socket.AF_INET6, socket.SOCK_STREAM) hostAddress = self._serverGetConnectionAddressTest( client, interface, 'getHost') peer = client.getpeername() hostname = socket.getnameinfo(peer, socket.NI_NUMERICHOST)[0] self.assertEqual( IPv6Address('TCP', hostname, *peer[1:]), hostAddress)
Example #3
Source File: resolver.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def override_system_resolver(resolver=None): """Override the system resolver routines in the socket module with versions which use dnspython's resolver. This can be useful in testing situations where you want to control the resolution behavior of python code without having to change the system's resolver settings (e.g. /etc/resolv.conf). The resolver to use may be specified; if it's not, the default resolver will be used. @param resolver: the resolver to use @type resolver: dns.resolver.Resolver object or None """ if resolver is None: resolver = get_default_resolver() global _resolver _resolver = resolver socket.getaddrinfo = _getaddrinfo socket.getnameinfo = _getnameinfo socket.getfqdn = _getfqdn socket.gethostbyname = _gethostbyname socket.gethostbyname_ex = _gethostbyname_ex socket.gethostbyaddr = _gethostbyaddr
Example #4
Source File: test_socket.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def testBadParameters(self): for address, flags in [ ( (0,0), 0), ( (0,"http"), 0), ( "localhost", 0), ( 0, 0), ( ("",), 0), ]: try: socket.getnameinfo(address, flags) except TypeError: pass except Exception, x: self.fail("Bad getnameinfo parameters (%s, %s) raised wrong exception: %s" % (str(address), flags, str(x))) else: self.fail("Bad getnameinfo parameters (%s, %s) failed to raise exception" % (str(address), flags))
Example #5
Source File: test_tcp.py From learn_python3_spider with MIT License | 6 votes |
def test_serverGetPeerOnIPv6(self): """ When a connection is accepted over IPv6, the server L{ITransport.getPeer} method returns an L{IPv6Address} giving the address on the remote end of the connection. """ interface = '::1' client = createTestSocket(self, socket.AF_INET6, socket.SOCK_STREAM) peerAddress = self._serverGetConnectionAddressTest( client, interface, 'getPeer') peer = client.getsockname() hostname = socket.getnameinfo(peer, socket.NI_NUMERICHOST)[0] self.assertEqual( IPv6Address('TCP', hostname, *peer[1:]), peerAddress)
Example #6
Source File: tcp.py From learn_python3_spider with MIT License | 6 votes |
def _setRealAddress(self, address): """ Set the resolved address of this L{_BaseBaseClient} and initiate the connection attempt. @param address: Depending on whether this is an IPv4 or IPv6 connection attempt, a 2-tuple of C{(host, port)} or a 4-tuple of C{(host, port, flow, scope)}. At this point it is a fully resolved address, and the 'host' portion will always be an IP address, not a DNS name. """ if len(address) == 4: # IPv6, make sure we have the scopeID associated hostname = socket.getnameinfo( address, socket.NI_NUMERICHOST | socket.NI_NUMERICSERV)[0] self.realAddress = tuple([hostname] + list(address[1:])) else: self.realAddress = address self.doConnect()
Example #7
Source File: tcp.py From learn_python3_spider with MIT License | 6 votes |
def _getrealname(addr): """ Return a 2-tuple of socket IP and port for IPv4 and a 4-tuple of socket IP, port, flowInfo, and scopeID for IPv6. For IPv6, it returns the interface portion (the part after the %) as a part of the IPv6 address, which Python 3.7+ does not include. @param addr: A 2-tuple for IPv4 information or a 4-tuple for IPv6 information. """ if len(addr) == 4: # IPv6 host = socket.getnameinfo( addr, socket.NI_NUMERICHOST | socket.NI_NUMERICSERV)[0] return tuple([host] + list(addr[1:])) else: return addr[:2]
Example #8
Source File: resolver.py From Cloudmare with GNU General Public License v3.0 | 6 votes |
def override_system_resolver(resolver=None): """Override the system resolver routines in the socket module with versions which use dnspython's resolver. This can be useful in testing situations where you want to control the resolution behavior of python code without having to change the system's resolver settings (e.g. /etc/resolv.conf). The resolver to use may be specified; if it's not, the default resolver will be used. @param resolver: the resolver to use @type resolver: thirdparty.dns.resolver.Resolver object or None """ if resolver is None: resolver = get_default_resolver() global _resolver _resolver = resolver socket.getaddrinfo = _getaddrinfo socket.getnameinfo = _getnameinfo socket.getfqdn = _getfqdn socket.gethostbyname = _gethostbyname socket.gethostbyname_ex = _gethostbyname_ex socket.gethostbyaddr = _gethostbyaddr
Example #9
Source File: resolver.py From bazarr with GNU General Public License v3.0 | 6 votes |
def override_system_resolver(resolver=None): """Override the system resolver routines in the socket module with versions which use dnspython's resolver. This can be useful in testing situations where you want to control the resolution behavior of python code without having to change the system's resolver settings (e.g. /etc/resolv.conf). The resolver to use may be specified; if it's not, the default resolver will be used. @param resolver: the resolver to use @type resolver: dns.resolver.Resolver object or None """ if resolver is None: resolver = get_default_resolver() global _resolver _resolver = resolver socket.getaddrinfo = _getaddrinfo socket.getnameinfo = _getnameinfo socket.getfqdn = _getfqdn socket.gethostbyname = _gethostbyname socket.gethostbyname_ex = _gethostbyname_ex socket.gethostbyaddr = _gethostbyaddr
Example #10
Source File: test__socket.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_getnameinfo(self): '''Tests _socket.getnameinfo()''' #sanity _socket.getnameinfo(("127.0.0.1", 80), 8) _socket.getnameinfo(("127.0.0.1", 80), 9) host, service = _socket.getnameinfo( ("127.0.0.1", 80), 8) self.assertEqual(service, '80') host, service = _socket.getnameinfo( ("127.0.0.1", 80), 0) self.assertEqual(service, "http") #IP gives a TypeError #self.assertRaises(SystemError, _socket.getnameinfo, ("127.0.0.1"), 8) #self.assertRaises(SystemError, _socket.getnameinfo, (321), 8) self.assertRaises(TypeError, _socket.getnameinfo, ("127.0.0.1"), '0') self.assertRaises(TypeError, _socket.getnameinfo, ("127.0.0.1", 80, 0, 0, 0), 8) self.assertRaises(_socket.gaierror, _socket.getnameinfo, ('no such host will ever exist', 80), 8)
Example #11
Source File: resolver.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def override_system_resolver(resolver=None): """Override the system resolver routines in the socket module with versions which use dnspython's resolver. This can be useful in testing situations where you want to control the resolution behavior of python code without having to change the system's resolver settings (e.g. /etc/resolv.conf). The resolver to use may be specified; if it's not, the default resolver will be used. @param resolver: the resolver to use @type resolver: dns.resolver.Resolver object or None """ if resolver is None: resolver = get_default_resolver() global _resolver _resolver = resolver socket.getaddrinfo = _getaddrinfo socket.getnameinfo = _getnameinfo socket.getfqdn = _getfqdn socket.gethostbyname = _gethostbyname socket.gethostbyname_ex = _gethostbyname_ex socket.gethostbyaddr = _gethostbyaddr
Example #12
Source File: test_tcp.py From learn_python3_spider with MIT License | 6 votes |
def test_serverGetPeerOnIPv6ScopeID(self): """ When a connection is accepted over IPv6, the server L{ITransport.getPeer} method returns an L{IPv6Address} giving the address on the remote end of the connection, including the scope identifier. """ interface = getLinkLocalIPv6Address() client = createTestSocket(self, socket.AF_INET6, socket.SOCK_STREAM) peerAddress = self._serverGetConnectionAddressTest( client, interface, 'getPeer') peer = client.getsockname() hostname = socket.getnameinfo(peer, socket.NI_NUMERICHOST)[0] self.assertEqual( IPv6Address('TCP', hostname, *peer[1:]), peerAddress)
Example #13
Source File: resolver.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def override_system_resolver(resolver=None): """Override the system resolver routines in the socket module with versions which use dnspython's resolver. This can be useful in testing situations where you want to control the resolution behavior of python code without having to change the system's resolver settings (e.g. /etc/resolv.conf). The resolver to use may be specified; if it's not, the default resolver will be used. @param resolver: the resolver to use @type resolver: dns.resolver.Resolver object or None """ if resolver is None: resolver = get_default_resolver() global _resolver _resolver = resolver socket.getaddrinfo = _getaddrinfo socket.getnameinfo = _getnameinfo socket.getfqdn = _getfqdn socket.gethostbyname = _gethostbyname socket.gethostbyname_ex = _gethostbyname_ex socket.gethostbyaddr = _gethostbyaddr
Example #14
Source File: resolver.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def override_system_resolver(resolver=None): """Override the system resolver routines in the socket module with versions which use dnspython's resolver. This can be useful in testing situations where you want to control the resolution behavior of python code without having to change the system's resolver settings (e.g. /etc/resolv.conf). The resolver to use may be specified; if it's not, the default resolver will be used. @param resolver: the resolver to use @type resolver: dns.resolver.Resolver object or None """ if resolver is None: resolver = get_default_resolver() global _resolver _resolver = resolver socket.getaddrinfo = _getaddrinfo socket.getnameinfo = _getnameinfo socket.getfqdn = _getfqdn socket.gethostbyname = _gethostbyname socket.gethostbyname_ex = _gethostbyname_ex socket.gethostbyaddr = _gethostbyaddr
Example #15
Source File: test_socket.py From medicare-demo with Apache License 2.0 | 6 votes |
def testBadParameters(self): for address, flags in [ ( (0,0), 0), ( (0,"http"), 0), ( "localhost", 0), ( 0, 0), ( ("",), 0), ]: try: socket.getnameinfo(address, flags) except TypeError: pass except Exception, x: self.fail("Bad getnameinfo parameters (%s, %s) raised wrong exception: %s" % (str(address), flags, str(x))) else: self.fail("Bad getnameinfo parameters (%s, %s) failed to raise exception" % (str(address), flags))
Example #16
Source File: test_socket.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def testBadParameters(self): for address, flags in [ ( (0,0), 0), ( (0,"http"), 0), ( "localhost", 0), ( 0, 0), ( ("",), 0), ]: try: socket.getnameinfo(address, flags) except TypeError: pass except Exception, x: self.fail("Bad getnameinfo parameters (%s, %s) raised wrong exception: %s" % (str(address), flags, str(x))) else: self.fail("Bad getnameinfo parameters (%s, %s) failed to raise exception" % (str(address), flags))
Example #17
Source File: resolver.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def restore_system_resolver(): """Undo the effects of override_system_resolver(). """ global _resolver _resolver = None socket.getaddrinfo = _original_getaddrinfo socket.getnameinfo = _original_getnameinfo socket.getfqdn = _original_getfqdn socket.gethostbyname = _original_gethostbyname socket.gethostbyname_ex = _original_gethostbyname_ex socket.gethostbyaddr = _original_gethostbyaddr
Example #18
Source File: resolver.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def restore_system_resolver(): """Undo the effects of override_system_resolver(). """ global _resolver _resolver = None socket.getaddrinfo = _original_getaddrinfo socket.getnameinfo = _original_getnameinfo socket.getfqdn = _original_getfqdn socket.gethostbyname = _original_gethostbyname socket.gethostbyname_ex = _original_gethostbyname_ex socket.gethostbyaddr = _original_gethostbyaddr
Example #19
Source File: base_events.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def getnameinfo(self, sockaddr, flags=0): return await self.run_in_executor( None, socket.getnameinfo, sockaddr, flags)
Example #20
Source File: base_events.py From android_universal with MIT License | 5 votes |
def getnameinfo(self, sockaddr, flags=0): return await self.run_in_executor( None, socket.getnameinfo, sockaddr, flags)
Example #21
Source File: test_socket.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def testRefCountGetNameInfo(self): # Testing reference count for getnameinfo import sys if hasattr(sys, "getrefcount"): try: # On some versions, this loses a reference orig = sys.getrefcount(__name__) socket.getnameinfo(__name__,0) except SystemError: if sys.getrefcount(__name__) <> orig: self.fail("socket.getnameinfo loses a reference")
Example #22
Source File: test_socket.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testInterpreterCrash(self): if sys.platform[:4] == 'java': return # Making sure getnameinfo doesn't crash the interpreter try: # On some versions, this crashes the interpreter. socket.getnameinfo(('x', 0, 0, 0), 0) except socket.error: pass # Need to implement binary AND for ints and longs
Example #23
Source File: resolver.py From Cloudmare with GNU General Public License v3.0 | 5 votes |
def restore_system_resolver(): """Undo the effects of override_system_resolver(). """ global _resolver _resolver = None socket.getaddrinfo = _original_getaddrinfo socket.getnameinfo = _original_getnameinfo socket.getfqdn = _original_getfqdn socket.gethostbyname = _original_gethostbyname socket.gethostbyname_ex = _original_gethostbyname_ex socket.gethostbyaddr = _original_gethostbyaddr
Example #24
Source File: test_socket.py From medicare-demo with Apache License 2.0 | 5 votes |
def testHostIdna(self): fqdn = u"\u043f\u0440\u0430\u0432\u0438\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e.\u0440\u0444" idn = "xn--80aealotwbjpid2k.xn--p1ai" ip = "95.173.135.62" try: import java.net.IDN except ImportError: try: socket.getnameinfo( (fqdn, 80), 0) except UnicodeEncodeError: pass except Exception, x: self.fail("International domain without java.net.IDN raised wrong exception: %s" % str(x)) else: self.fail("International domain without java.net.IDN failed to raise exception")
Example #25
Source File: test_socket.py From medicare-demo with Apache License 2.0 | 5 votes |
def testHost(self): for address, flags, expected in [ ( ("www.python.org", 80), 0, "dinsdale.python.org"), ( ("www.python.org", 80), socket.NI_NUMERICHOST, "82.94.164.162" ), ( ("www.python.org", 80), socket.NI_NAMEREQD, "dinsdale.python.org"), ( ("82.94.164.162", 80), socket.NI_NAMEREQD, "dinsdale.python.org"), ]: result = socket.getnameinfo(address, flags) self.failUnlessEqual(result[0], expected)
Example #26
Source File: test_socket.py From medicare-demo with Apache License 2.0 | 5 votes |
def testPort(self): for address, flags, expected in [ ( ("127.0.0.1", 25), 0, "smtp" ), ( ("127.0.0.1", 25), socket.NI_NUMERICSERV, 25 ), ( ("127.0.0.1", 513), socket.NI_DGRAM, "who" ), ( ("127.0.0.1", 513), 0, "login"), ]: result = socket.getnameinfo(address, flags) self.failUnlessEqual(result[1], expected)
Example #27
Source File: test_socket.py From medicare-demo with Apache License 2.0 | 5 votes |
def testInterpreterCrash(self): if sys.platform[:4] == 'java': return # Making sure getnameinfo doesn't crash the interpreter try: # On some versions, this crashes the interpreter. socket.getnameinfo(('x', 0, 0, 0), 0) except socket.error: pass # Need to implement binary AND for ints and longs
Example #28
Source File: test_socket.py From medicare-demo with Apache License 2.0 | 5 votes |
def testRefCountGetNameInfo(self): # Testing reference count for getnameinfo import sys if hasattr(sys, "getrefcount"): try: # On some versions, this loses a reference orig = sys.getrefcount(__name__) socket.getnameinfo(__name__,0) except SystemError: if sys.getrefcount(__name__) <> orig: self.fail("socket.getnameinfo loses a reference")
Example #29
Source File: test_socket.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_flowinfo(self): self.assertRaises(OverflowError, socket.getnameinfo, (support.HOSTv6, 0, 0xffffffff), 0) with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: self.assertRaises(OverflowError, s.bind, (support.HOSTv6, 0, -10))
Example #30
Source File: test_socket.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_getnameinfo(self): # only IP addresses are allowed self.assertRaises(OSError, socket.getnameinfo, ('mail.python.org',0), 0)