Skip to content

Commit 10150da

Browse files
authored
Merge pull request #91 from linted/master
Update IP validation to support IPv6
2 parents df9311a + 73f4503 commit 10150da

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

VHostScan/lib/helpers/wordlist_helper.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from .file_helper import get_combined_word_lists
33
from pkg_resources import resource_filename
4-
4+
from ipaddress import ip_address
55

66
DEFAULT_WORDLIST_FILE = resource_filename(
77
'VHostScan', 'wordlists/virtual-host-scanning.txt')
@@ -74,9 +74,6 @@ def set_words(self, words_type, words):
7474

7575
def valid_ip(self, address):
7676
try:
77-
host_bytes = address.split('.')
78-
valid = [int(b) for b in host_bytes]
79-
valid = [b for b in valid if b >= 0 and b <= 255]
80-
return len(host_bytes) == 4 and len(valid) == 4
77+
return ip_address(address) is not None
8178
except:
8279
return False

tests/helpers/test_wordlist_helper.py

+14
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ def test_ip_using_suffix(self):
6161
wordlist, wordlist_types = self.wordlist.get_wordlist(None,None,suffix)
6262
self.assertEqual(wordlist,stdin_wordlist)
6363

64+
def test_ipv6_using_prefix(self):
65+
stdin_wordlist = ['::1']
66+
prefix = 'dev-'
67+
with patch('VHostScan.lib.helpers.wordlist_helper.WordList.get_stdin_wordlist', return_value=stdin_wordlist):
68+
wordlist, wordlist_types = self.wordlist.get_wordlist(None, prefix)
69+
self.assertEqual(wordlist, stdin_wordlist)
70+
71+
def test_ipv6_using_suffix(self):
72+
stdin_wordlist = ['::1']
73+
suffix = 'test'
74+
with patch('VHostScan.lib.helpers.wordlist_helper.WordList.get_stdin_wordlist', return_value=stdin_wordlist):
75+
wordlist, wordlist_types = self.wordlist.get_wordlist(None,None,suffix)
76+
self.assertEqual(wordlist,stdin_wordlist)
77+
6478
def test_word_with_prefix(self):
6579
stdin_wordlist = ['www','www2','www3']
6680
expected_wordlist = stdin_wordlist + ['dev-www','dev-www2','dev-www3']

0 commit comments

Comments
 (0)