mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 04:48:00 +01:00
Implemented basic IPv6 support -- needs HEAVY testing
This commit is contained in:
@@ -152,18 +152,19 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
|||||||
def set_defaults(self, widget=None, event=None):
|
def set_defaults(self, widget=None, event=None):
|
||||||
""" Put some default values into entries to help the user out. """
|
""" Put some default values into entries to help the user out. """
|
||||||
self.txt_ip.set_text(self.txt_ip.get_text().strip())
|
self.txt_ip.set_text(self.txt_ip.get_text().strip())
|
||||||
ipAddress = self.txt_ip.get_text() # For easy typing :)
|
ip = self.txt_ip.get_text() # For easy typing :)
|
||||||
netmask = self.txt_netmask
|
netmask = self.txt_netmask
|
||||||
gateway = self.txt_gateway
|
gateway = self.txt_gateway
|
||||||
ip_parts = misc.IsValidIP(ipAddress)
|
if misc.IsValidIP(ip):
|
||||||
if ip_parts:
|
# Only do these things if it's IPv4
|
||||||
|
if misc.IsValidIPv4(ip):
|
||||||
if stringToNone(gateway.get_text()) is None: # Make sure the gateway box is blank
|
if stringToNone(gateway.get_text()) is None: # Make sure the gateway box is blank
|
||||||
# Fill it in with a .1 at the end
|
# Fill it in with a .1 at the end
|
||||||
gateway.set_text('.'.join(ip_parts[0:3]) + '.1')
|
gateway.set_text(ip[:ip.rindex('.')] + '.1')
|
||||||
|
|
||||||
if stringToNone(netmask.get_text()) is None: # Make sure the netmask is blank
|
if stringToNone(netmask.get_text()) is None: # Make sure the netmask is blank
|
||||||
netmask.set_text('255.255.255.0') # Fill in the most common one
|
netmask.set_text('255.255.255.0') # Fill in the most common one
|
||||||
elif ipAddress != "":
|
elif ip != '':
|
||||||
error(None, _('Invalid IP address entered.'))
|
error(None, _('Invalid IP address entered.'))
|
||||||
|
|
||||||
def reset_static_checkboxes(self):
|
def reset_static_checkboxes(self):
|
||||||
|
|||||||
@@ -18,6 +18,18 @@ class TestMisc(unittest.TestCase):
|
|||||||
def test_valid_ip_3(self):
|
def test_valid_ip_3(self):
|
||||||
self.assertTrue(misc.IsValidIP('10.0.1.1'))
|
self.assertTrue(misc.IsValidIP('10.0.1.1'))
|
||||||
|
|
||||||
|
def test_valid_ip_4(self):
|
||||||
|
self.assertTrue(misc.IsValidIP('::'))
|
||||||
|
|
||||||
|
def test_valid_ip_5(self):
|
||||||
|
self.assertTrue(misc.IsValidIP('::1'))
|
||||||
|
|
||||||
|
def test_valid_ip_6(self):
|
||||||
|
self.assertTrue(misc.IsValidIP('FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF'))
|
||||||
|
|
||||||
|
def test_valid_ip_7(self):
|
||||||
|
self.assertTrue(misc.IsValidIP('2001:0db8:85a3:0000:0000:8a2e:0370:7334'))
|
||||||
|
|
||||||
def test_invalid_ip_1(self):
|
def test_invalid_ip_1(self):
|
||||||
self.assertFalse(misc.IsValidIP('-10.0.-1.-1'))
|
self.assertFalse(misc.IsValidIP('-10.0.-1.-1'))
|
||||||
|
|
||||||
@@ -27,6 +39,18 @@ class TestMisc(unittest.TestCase):
|
|||||||
def test_invalid_ip_3(self):
|
def test_invalid_ip_3(self):
|
||||||
self.assertFalse(misc.IsValidIP('1000.0.0.1'))
|
self.assertFalse(misc.IsValidIP('1000.0.0.1'))
|
||||||
|
|
||||||
|
def test_invalid_ip_4(self):
|
||||||
|
self.assertFalse(misc.IsValidIP(':'))
|
||||||
|
|
||||||
|
def test_invalid_ip_5(self):
|
||||||
|
self.assertFalse(misc.IsValidIP('1:'))
|
||||||
|
|
||||||
|
def test_invalid_ip_6(self):
|
||||||
|
self.assertFalse(misc.IsValidIP('ZZZZ:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF'))
|
||||||
|
|
||||||
|
def test_invalid_ip_7(self):
|
||||||
|
self.assertFalse(misc.IsValidIP('2001:0db8:85Z3:0000:0000:8a2e:0370:7334'))
|
||||||
|
|
||||||
def test_run_valid_regex(self):
|
def test_run_valid_regex(self):
|
||||||
import re
|
import re
|
||||||
regex = re.compile('.*(ABC.EFG).*')
|
regex = re.compile('.*(ABC.EFG).*')
|
||||||
|
|||||||
22
wicd/misc.py
22
wicd/misc.py
@@ -33,6 +33,7 @@ from subprocess import Popen, STDOUT, PIPE, call
|
|||||||
from commands import getoutput
|
from commands import getoutput
|
||||||
from itertools import repeat, chain, izip
|
from itertools import repeat, chain, izip
|
||||||
from pipes import quote
|
from pipes import quote
|
||||||
|
import socket
|
||||||
|
|
||||||
from wicd.translations import _
|
from wicd.translations import _
|
||||||
|
|
||||||
@@ -173,15 +174,26 @@ def IsValidIP(ip):
|
|||||||
""" Make sure an entered IP is valid. """
|
""" Make sure an entered IP is valid. """
|
||||||
if not ip: return False
|
if not ip: return False
|
||||||
|
|
||||||
ipNumbers = ip.split('.')
|
if not IsValidIPv4(ip):
|
||||||
if len(ipNumbers) < 4:
|
if not IsValidIPv6(ip):
|
||||||
return False
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
for number in ipNumbers:
|
def IsValidIPv4(ip):
|
||||||
if not number.isdigit() or int(number) > 255:
|
''' Make sure an entered IP is a valid IPv4. '''
|
||||||
|
try:
|
||||||
|
socket.inet_pton(socket.AF_INET, ip)
|
||||||
|
except (TypeError, socket.error):
|
||||||
return False
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
return ipNumbers
|
def IsValidIPv6(ip):
|
||||||
|
''' Make sure an entered IP is a valid IPv6. '''
|
||||||
|
try:
|
||||||
|
socket.inet_pton(socket.AF_INET6, ip)
|
||||||
|
except (TypeError, socket.error):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def PromptToStartDaemon():
|
def PromptToStartDaemon():
|
||||||
""" Prompt the user to start the daemon """
|
""" Prompt the user to start the daemon """
|
||||||
|
|||||||
Reference in New Issue
Block a user