我已经在网络服务器上找到了一些PDF文件,暂时我想隐藏它们(即让它们返回404)。这可以在带有重写规则的web.config文件中完成吗?
在Apache中你可以这样做:
$lookingForId = 100;
Basemodel::whereHas('attachedmodels', function ($query) use ($lookingForId) {
$query->where('id', '=', $lookingForId);
})->get();
如何使用IIS实现相同的效果?
答案 0 :(得分:1)
实现此目的的一种方法是在IIS中使用 HiddenSegments 。 HiddenSegments会使客户端无法访问URL。此外,IIS将向客户端返回import requests
import sys
import threading
import signal
import time
code = 736479509787350
url = 'https://www.test.ing/codes/'
file = open("valid-codes.txt", "a")
log = open("log.txt", "a")
code_lock = threading.Lock()
file_lock = threading.Lock()
log_lock = threading.Lock()
terminate = False
class bot(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
@classmethod
def getCode(self):
global code
code_lock.acquire()
work_code = code
try:
code += 1
finally:
code_lock.release()
return work_code
@classmethod
def checkCode(self, work_code):
try:
if(code % 1000000 == 0):
print("Code "+str(work_code)+" is being checked...\n")
html = requests.get(url+str(work_code))
html.encoding = 'utf-8'
if(not 'Page Not Found' in html.text):
time.sleep(0.5)
html = requests.get(url+str(work_code)+":999999999")
html.encoding = 'utf-8'
return 'Page Not Found' in html.text
except requests.exceptions.ConnectionError:
#print("Connection Error! Retrying...\n")
time.sleep(1)
return self.checkCode(work_code)
except KeyboardInterrupt:
self.logCode(work_code)
sys.exit()
@classmethod
def storeCode(self, work_code):
global file_lock
global file
file_lock.acquire()
try:
file.write(str(work_code)+'\n')
finally:
file_lock.release()
@classmethod
def logCode(self, work_code):
global log_lock
global log
log_lock.acquire()
try:
log.write(str(work_code)+'\n')
finally:
log_lock.release()
@classmethod
def run(self):
global terminate
while(not terminate):
work_code = self.getCode()
if(self.checkCode(work_code)):
print("Code "+str(work_code)+" is a valid code!\n")
self.storeCode(work_code)
self.logCode(work_code)
def main(threads = 16):
#bots = [threading.Thread(target=bot) for bot in range(threads)]
bots = []
#url = 'https://www.facebook.com/leticia.m.demenezes/posts/'
#file = open("valid-codes.txt", "a")
#log = open("log.txt", "a")
#code_lock = threading.Lock()
#file_lock = threading.Lock()
#log_lock = threading.Lock()
def signal_handler(signal, frame):
global terminate
print('Exiting...\n')
log_lock.acquire()
try:
log.write("\n\n"+str(time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()))+"\n")
finally:
log_lock.release()
terminate = True
for bot in bots:
bot.join()
sys.exit(0)
#for bot in bots:
# bot.start()
for i in range(threads):
t = bot()
bots.append(t)
t.start()
signal.signal(signal.SIGINT, signal_handler)
while True:
signal.pause()
main()
错误并记录HTTP 404
HTTP子状态。
404.8
编辑1:
您还可以使用RequestFiltering拒绝客户端的PDF扩展。 <configuration>
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="pathofpages" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
将被退回。所有PDF文件请求都将被拒绝。
来自IIS.net
在“请求筛选”窗格中,单击“文件扩展名”选项卡,然后单击“确定” 然后单击“操作”窗格中的“拒绝文件扩展名...”。