我遵循了这个脚本的教程,当我运行它时...没有任何反应...我点击运行模块,它只是跳过一行并等待下一个输入? nothign实际发生(即我的测试文件的密码显示)
lst=['00:00', '01:45', '1:45', '001:59','23:46','32:00','09:75']
答案 0 :(得分:0)
看起来您可能正在引用未定义的变量
<?php
include 'sessions.php';
$fileName = "../writeable/users.txt";
$userid = $_GET['newUserName'];
$Email = $_GET['newEmail']; // changed to get
$Users = file($fileName);
$userstring = "";
$found = false;
for($i=0; $i < count($Users); $i++) {
$row = explode(",", $Users[$i]); // the name row here is wrong, the var $Users is equivalent to rows, this represents each 'column'
foreach($row as $k => $c){
if($found){ // since it's unique
$userstring .= $row[0].",".$row[1].",".$row[2].",".$row[3].""; // the \n is already part of 'inactive'
break;
}elseif($c===$Email){
$userstring .= $row[0].",".$row[1].",".$row[2].",active\n";
$_SESSION['active'] = TRUE;
$found = true;
break; // no need to keep checking if it's unique
}elseif($k == count($row)-1){ // if you checked all the 'columns' of that row and didn't find the match, add it without active
$userstring .= $row[0].",".$row[1].",".$row[2].",".$row[3].""; // the \n is already part of 'inactive'
}
}
}
//destroy the users.txt file
if (file_exists($fileName)){
if(unlink($fileName)){
echo "File destroyed, will now be recreated";
}
}
else
echo "<p>Unable to delete this file<p>";
$Userfile = fopen($fileName, "w+"); //recreate the file
// removed
//$userstring = implode(",", $Users); //make the array into a string.
fwrite($Userfile, $userstring); //write the string userstring into userfile
if(!file_exists($fileName)){
echo "<p>This file was not written<p>";
}
?>
您的代码中没有x var。你可能想要行作为你的var。
这就是你的try except语句不会触发print命令的原因。
答案 1 :(得分:0)
空文件夹表示密码无法正常工作且文件未解压缩。我编写了我的脚本 - 当您尝试进行错误的密码时,目标路径(即桌面)上会出现一个空的存档文件夹。 但是,如果密码正确,那么您可以正确地看到内容。所以空文件夹意味着没有正确打开,这可能意味着密码错误。
Docs on strip()表示您需要指定要剥离的内容。如果要剥离空格,请尝试添加\ n作为strip()参数,因此strip(\ n)。我认为您正在提取正确的密码,只包含空格,因此您的密码无效。
编辑 - 您不需要指定删除空格。
&#34;如果省略字符或无,则删除空白字符。&#34;
docs.python.org/2/library/string.html#string.strip
首先要做的事情:
From documentation,当您打开文件时,最好使用&#39;&#39;带文件对象的关键字。我会将其应用于单词列表和存档文件。这意味着它们将被正确关闭,而不指定&#34;关闭&#34;。
with open("words.txt", "r") as the_text:
什么是x?你还没有在任何地方宣布它。要查看列表,请删除行并创建您想要的密码:
with open("words.txt", "r") as the_text:
for entry in the_text.readlines():
password = entry.strip('\n')
这会遍历文本中的每一行,删除空格(\ n)并使用生成的单词作为密码。
然后您需要将该密码传递给.zip文件。我会使用try / except来引发自定义错误(在这种情况下没有错误消息)并继续尝试直到出现问题。
try:
with zipfile.ZipFile('arch.zip', 'r') as zf:
zf.extractall(pwd=password)
print '[+] Found password = ' + password + '\n'
exit(0)
except:
pass
再一次,我在这里使用&#39;打开zip文件并使用变量zf 如果密码匹配且文件打开,则会打印出成功的密码并退出。如果没有退出(0),它将继续尝试匹配密码,即使它找到了正确的密码。
要记住的其他事情是Python是垃圾。它很有效但很慢。关于其他建议的Stack的答案很多,比我更了解的人。
我目前正在学习Python 2.7并希望这有用。我完成的脚本(测试并使用476k英语单词列表)
with open("words.txt", "r") as the_text:
for entry in the_text.readlines():
password = entry.strip('\n')
try:
with zipfile.ZipFile('arch.zip', 'r') as zf:
zf.extractall(pwd=password)
print '[+] Found password = ' + password + '\n'
exit(0)
except:
pass