Initial Commit
commit
bc0bea9632
|
@ -0,0 +1,9 @@
|
|||
bin/
|
||||
obj/
|
||||
|
||||
*.depend
|
||||
*.layout
|
||||
|
||||
/*.dll
|
||||
/*.txt
|
||||
/*.exe
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "CurlWrapper"]
|
||||
path = CurlWrapper
|
||||
url = https://github.com/kiritow/CurlWrapper
|
|
@ -0,0 +1,57 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="BaiduNetDiskLinkCheck" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/BaiduNetDiskLinkCheck" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Debug/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/BaiduNetDiskLinkCheck" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
<Add directory="CurlWrapper/include" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add library="CurlWrapper/lib/x86/libcurl.lib" />
|
||||
</Linker>
|
||||
<Unit filename="CurlWrapper/include/NetworkWrapper.h" />
|
||||
<Unit filename="CurlWrapper/include/curl/curl.h" />
|
||||
<Unit filename="CurlWrapper/include/curl/curlver.h" />
|
||||
<Unit filename="CurlWrapper/include/curl/easy.h" />
|
||||
<Unit filename="CurlWrapper/include/curl/mprintf.h" />
|
||||
<Unit filename="CurlWrapper/include/curl/multi.h" />
|
||||
<Unit filename="CurlWrapper/include/curl/stdcheaders.h" />
|
||||
<Unit filename="CurlWrapper/include/curl/system.h" />
|
||||
<Unit filename="CurlWrapper/include/curl/typecheck-gcc.h" />
|
||||
<Unit filename="CurlWrapper/src/NetworkWrapper.cpp" />
|
||||
<Unit filename="main.cpp" />
|
||||
<Extensions>
|
||||
<code_completion />
|
||||
<envvars />
|
||||
<debugger />
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
|
@ -0,0 +1 @@
|
|||
Subproject commit cc89db4f21718ad57f5b9eb04f705daaa9cee558
|
|
@ -0,0 +1,127 @@
|
|||
#include "NetworkWrapper.h"
|
||||
#include "json.hpp"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
using namespace std;
|
||||
using namespace nlohmann;
|
||||
|
||||
#define USER_AGENT "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36"
|
||||
|
||||
string vastr;
|
||||
string unstr;
|
||||
vector<string> errdic;
|
||||
|
||||
/// Return: -1 Failed, 0 URL broken, 1 URL ok, 2 URL unknown
|
||||
int CheckURL(const string& url)
|
||||
{
|
||||
string turl=url;
|
||||
string content;
|
||||
|
||||
while(true)
|
||||
{
|
||||
HTTPConnection c;
|
||||
c.setUserAgent(USER_AGENT);
|
||||
c.setURL(turl);
|
||||
c.setDataOutputBuffer(nullptr,0);
|
||||
c.setSSLVerifyHost(false);
|
||||
c.setSSLVerifyPeer(false);
|
||||
|
||||
//cout<<"Performing on "<<turl<<endl;
|
||||
|
||||
if(c.perform()!=0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
//cout<<"ResponseCode: "<<c.getResponseCode()<<endl;
|
||||
|
||||
if(c.getResponseCode()!=200)
|
||||
{
|
||||
if(c.getResponseCode()==302)
|
||||
{
|
||||
turl=c.getRedirectURL();
|
||||
//cout<<"Redirect to "<<turl<<endl;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
content=string((char*)c.getDataOutputBuffer(),c.getDataOutputBufferLength());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
do {
|
||||
ofstream ofs("out.txt");
|
||||
ofs<<content<<endl;
|
||||
}while(0);
|
||||
//*/
|
||||
|
||||
if(content.find(vastr)!=string::npos)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(content.find(unstr)!=string::npos)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
for(auto& s:errdic)
|
||||
{
|
||||
if(content.find(s)!=string::npos)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// ...
|
||||
return 3;
|
||||
}
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
do{
|
||||
ifstream ifs("strings_utf8.json");
|
||||
string str,tmp;
|
||||
while(getline(ifs,tmp)) str.append(tmp);
|
||||
json j=json::parse(str);
|
||||
vastr=j["ValidContent"];
|
||||
unstr=j["UnknownContent"];
|
||||
for(auto& s:j["ErrorContent"])
|
||||
{
|
||||
errdic.push_back(s["content"].get<string>());
|
||||
}
|
||||
}while(0);
|
||||
|
||||
if(argc==1)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
cout<<"Please input URL to check:"<<endl;
|
||||
string url;
|
||||
if(getline(cin,url))
|
||||
{
|
||||
cout<< [&](){switch(CheckURL(url)){
|
||||
case -1:return "Internal Error";
|
||||
case 0:return "URL Broken";
|
||||
case 1:return "URL OK";
|
||||
case 2:return "URL Unknown Status";
|
||||
default:return "Wrong Status";}}() << endl;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<< [&](){switch(CheckURL(argv[1])){
|
||||
case -1:return "Internal Error";
|
||||
case 0:return "URL Broken";
|
||||
case 1:return "URL OK";
|
||||
case 2:return "URL Unknown Status";
|
||||
default:return "Wrong Status";}}() << endl;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"ValidContent" : "百度网盘-分享无限制",
|
||||
"ErrorContent" : [
|
||||
{
|
||||
"name":"Link outdated",
|
||||
"content":"<title>百度网盘-链接已失效</title>"
|
||||
},
|
||||
{
|
||||
"name":"Link not exist",
|
||||
"content":"<title>百度网盘-链接不存在</title>"
|
||||
}
|
||||
],
|
||||
"UnknownContent": "<title>百度网盘 请输入提取密码</title>"
|
||||
}
|
Reference in New Issue