Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.

Commit f8f0503

Browse files
authored
Merge pull request #160 from lixiaoy1/ip_fix
Get all IPs
2 parents e15c1d0 + d279488 commit f8f0503

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

conf/common.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,19 @@ def addressToNetwork(self,ip,net):
5757

5858
def getIpByHostInSubnet(self, hostname, subnet ):
5959
"Get IP by hostname and filter with subnet"
60-
(hostname, aliaslist, ipaddrlist) = socket.gethostbyname_ex(hostname)
60+
stdout, stderr = pdsh('root', [hostname] ,"ifconfig", option = "check_return")
61+
if len(stderr):
62+
printout("ERROR", 'Error to get ips: %s' % stderr)
63+
sys.exit()
64+
ipaddrlist = []
65+
res = re.findall("inet addr:\d+\.\d+\.\d+\.\d+",stdout)
66+
for item in res:
67+
b = item.split(':')
68+
if b[1] != "127.0.0.1":
69+
ipaddrlist.append(b[1])
70+
if len(ipaddrlist) == 0:
71+
printout("ERROR", "No IP found")
72+
sys.exit()
6173
try:
6274
network, netmask = self.networkMask(subnet)
6375
except:

0 commit comments

Comments
 (0)