Exemple #1
0
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 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)
Exemple #3
0
 def test_get_ip_for_hostname(self):
     tmp = get_ip_for_hostname(socket.gethostname())
     self.assertTrue("." in tmp)
     self.assertTrue(isinstance(tmp, str))
Exemple #4
0
 def test_get_ip_for_hostname_not_found(self):
     tmp = get_ip_for_hostname("foo.bar")
     self.assertTrue(tmp is None)
Exemple #5
0
 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))
Exemple #6
0
 def test_get_ip_for_hostname_auto(self):
     tmp = get_ip_for_hostname("AUTO")
     self.assertEquals(tmp, "AUTO")
     self.assertTrue(isinstance(tmp, str))
Exemple #7
0
 def test_get_ip_for_hostname(self):
     tmp = get_ip_for_hostname(socket.gethostname())
     self.assertTrue("." in tmp)
     self.assertTrue(isinstance(tmp, str))
Exemple #8
0
 def test_get_ip_for_hostname_not_found(self):
     tmp = get_ip_for_hostname("foo.bar")
     self.assertTrue(tmp is None)
Exemple #9
0
 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))
Exemple #10
0
 def test_get_ip_for_hostname_auto(self):
     tmp = get_ip_for_hostname("AUTO")
     self.assertEquals(tmp, "AUTO")
     self.assertTrue(isinstance(tmp, str))