Created
February 20, 2018 14:37
-
-
Save bzdgn/3facb3c3315ed35c14f76cc00f20bf43 to your computer and use it in GitHub Desktop.
Simple Host Name Resolver Example In Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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