示例#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)
示例#2
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)
示例#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))
示例#4
0
 def test_get_ip_for_hostname_not_found(self):
     tmp = get_ip_for_hostname("foo.bar")
     self.assertTrue(tmp is None)
示例#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))
示例#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))
示例#7
0
文件: test_net.py 项目: frdcms/mfcom
 def test_get_ip_for_hostname(self):
     tmp = get_ip_for_hostname(socket.gethostname())
     self.assertTrue("." in tmp)
     self.assertTrue(isinstance(tmp, str))
示例#8
0
文件: test_net.py 项目: frdcms/mfcom
 def test_get_ip_for_hostname_not_found(self):
     tmp = get_ip_for_hostname("foo.bar")
     self.assertTrue(tmp is None)
示例#9
0
文件: test_net.py 项目: frdcms/mfcom
 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))
示例#10
0
文件: test_net.py 项目: frdcms/mfcom
 def test_get_ip_for_hostname_auto(self):
     tmp = get_ip_for_hostname("AUTO")
     self.assertEquals(tmp, "AUTO")
     self.assertTrue(isinstance(tmp, str))