Python method for listing IPv4 vs IPv6 rules
Hello, all.
I have a question about listing out IPv4 vs IPv6 rules using Python. While working with the Python package PyUFW (https:/
1 allow 22/tcp
2 allow 80
3 allow 443
4 allow 22/tcp
5 allow 80
6 allow 443
After some investigation, it appears to me that the culprit for this behavior actually lies with the UFW source code. In the source code there is an object that stores IPv4 and IPv6 rules in separate lists. Those lists are then accessed with the following method:
def get_rules(self):
'''Return list of all rules'''
return self.rules + self.rules6
The issue with this is that the returned list doesn't contain an indication of what IP version each item corresponds to.
Is there a different method that allows me to distinguish between IPv4 and IPv6 rules? I could always access the object's variables directly (see example below), but I don't think that's best practice.
rules_ipv4 = backend.rules
rules_ipv6 = backend.rules6
Please let me know what you all think as well as if you have any questions. Thanks!
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- Ubuntu ufw Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Kevin Tate for more information if necessary.