Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for GNU hostname command #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions gufw/gufw/model/ufw_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# along with Gufw; if not, see http://www.gnu.org/licenses for more
# information.

import time, os, shutil, subprocess, configparser
import time, os, shutil, subprocess, configparser, socket


class Backend():
Expand Down Expand Up @@ -469,15 +469,38 @@ def get_net_interfaces(self):

return result

def get_net_ip(self):
cmd_ip = ['hostname', '--all-ip-addresses']
cmd = self._run_cmd(cmd_ip)
ips = cmd.split('\n')

if len(ips) > 0:
return ips[0].strip()
def check_valid_ip(self, ip):
try:
socket.inet_aton(ip)
return True
except:
return False

def get_net_ip(self, gnu_hostname=False):
if not gnu_hostname:
cmd_ip = ['hostname', '--all-ip-addresses']
cmd = self._run_cmd(cmd_ip)
ips = cmd.split('\n')

if len(ips) > 0:
ip_str = ips[0].strip()
if self.check_valid_ip(ip_str):
return ip_str
else:
return self.get_net_ip(gnu_hostname=True)
else:
return '127.0.0.1'
else:
return '127.0.0.1'
cmd_ip = ['hostname', '--ip-addresses']
cmd = self._run_cmd(cmd_ip)
ips = cmd.split(' ')

if len(ips) > 0:
ip_str = ips[0].strip()
if self.check_valid_ip(ip_str):
return ip_str
else:
return '127.0.0.1'

def get_listening_report(self):
return_report = []
Expand Down