updated get_ipv4
This commit is contained in:
parent
7d124cf751
commit
cc408237d9
@ -172,14 +172,25 @@ class LXC(LinuxMachine):
|
||||
"""
|
||||
return self.bridge
|
||||
|
||||
def get_ipv4(self):
|
||||
def get_ipv4(self, netmask: bool = False):
|
||||
"""
|
||||
Get IPv4
|
||||
:return: ipv4
|
||||
"""
|
||||
if self.ipv4 == "dhcp":
|
||||
if self.is_running():
|
||||
return super().get_ipv4()
|
||||
if self.has_program("ip"):
|
||||
if netmask:
|
||||
ip = self.run_command(
|
||||
"""ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 """)
|
||||
return ip
|
||||
|
||||
ip = self.run_command(
|
||||
"""ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'""")
|
||||
return ip
|
||||
|
||||
elif self.has_program("ifconfig"):
|
||||
return self.run_command(command="ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'")
|
||||
|
||||
return self.ipv4
|
||||
|
||||
|
@ -29,6 +29,7 @@ class LinuxMachine():
|
||||
return self.run_command("free -m | grep Mem | awk '{print $2}'")
|
||||
|
||||
def get_ipv4(self):
|
||||
"""Get IPv4 address"""
|
||||
if self.has_program("ip"):
|
||||
return self.run_command("""ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'""")
|
||||
elif self.has_program("ifconfig"):
|
||||
|
Loading…
Reference in New Issue
Block a user