1. Create a targets file
VI Targets
$cat targets
Rpc-dcom 10.10.20.1.10.10.20.4
sql-sa-blank-pw10.10.20.27.10.10.20.28
2. Python
>>> targets_file = open (' Targets ', ' r ')//opening file as read-only
>>> lines = Targets_file.readlines ()
>>> lines
[' rpc-dcom \t\t10.10.20.1.10.10.20.4\n ', ' sql-sa-blank-pw\t\t10.10.20.27.10.10.20.28\n ']
>>> lines_dictionary = {}//definition dictionary
>>> in lines://Loop writes values to the dictionary
... one_line = Line.split ()
... line_key = one_line[0]
... line_value = one_line[1]
... lines_dictionary[line_key] = Line_value
>>> lines_dictionary
{' rpc-dcom ': ' 10.10.20.1.10.10.20.4 ', ' sql-sa-blank-pw ': ' 10.10.20.27.10.10.20.28 '}
>>> for key in Lines_dictionary.keys ()://extract keys and values separately
... targets_string = Lines_dictionary[key]
... targets_list = Targets_string.split (', ')
... targets_number = len (targets_list)
... filename = key + ' _ ' + str (targets_number) + ' _targets '
... vuln_file = open (filename, ' W ')
... for vuln_target in targets_list:
... vuln_file.write (vuln_target + ' \ n ')
... vuln_file.close ()
Two files generated rpc-dcom_1_targets and sql-sa-blank-pw_1_targets
Xfqdemacbook-pro:desktop admin_zoe$ ls
$RECYCLE. BIN
Rpc-dcom_1_targets
Sql-sa-blank-pw_1_targets
Xfqdemacbook-pro:desktop admin_zoe$ Cat Rpc-dcom_1_targets
10.10.20.1.10.10.20.4
Xfqdemacbook-pro:desktop admin_zoe$ Cat Sql-sa-blank-pw_1_targets
10.10.20.27.10.10.20.28
Python file access