Skip to content

Instantly share code, notes, and snippets.

@bzdgn
Created February 20, 2018 14:37
Show Gist options
  • Save bzdgn/3facb3c3315ed35c14f76cc00f20bf43 to your computer and use it in GitHub Desktop.
Save bzdgn/3facb3c3315ed35c14f76cc00f20bf43 to your computer and use it in GitHub Desktop.
Simple Host Name Resolver Example In Python
import socket
class Resolver:
def __init__(self):
self._cache = {}
def __call__(self, host):
if host not in self._cache:
self._cache[host] = socket.gethostbyname(host)
return self._cache[host]
def listCache(self):
for c in self._cache:
print("Host Name: ", c, " IP Address: ", self._cache[c])
r = Resolver()
r("google.com")
r("eksisozluk.com")
r("amazon.com")
r.listCache()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment