def main(): parser = argparse.ArgumentParser(description=DESCRIPTION) parser.add_argument("hostname", nargs='?', help="hostname to resolve as ip (can be empty)") args = parser.parse_args() if args.hostname is None: res = get_real_ip() else: res = get_ip_for_hostname(args.hostname) if res is not None: print(res) else: sys.exit(1)
def test_get_ip_for_hostname(self): tmp = get_ip_for_hostname(socket.gethostname()) self.assertTrue("." in tmp) self.assertTrue(isinstance(tmp, str))
def test_get_ip_for_hostname_not_found(self): tmp = get_ip_for_hostname("foo.bar") self.assertTrue(tmp is None)
def test_get_ip_for_hostname_localhost(self): tmp = get_ip_for_hostname("localhost") self.assertEquals(tmp, "127.0.0.1") self.assertTrue(isinstance(tmp, str))
def test_get_ip_for_hostname_auto(self): tmp = get_ip_for_hostname("AUTO") self.assertEquals(tmp, "AUTO") self.assertTrue(isinstance(tmp, str))