This commit is contained in:
cora32 2015-12-12 02:13:28 +03:00
parent 90d94b8a3a
commit 4cf3b15f36
4 changed files with 266 additions and 43 deletions

View File

@ -211,6 +211,18 @@ int Connector::nConnect(const char* ip, const int port, std::string *buffer,
|| res == CURLE_SEND_ERROR
|| res == CURLE_RECV_ERROR
) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("NConnect failed (curl_code: " + QString::number(res) + ") [<a href=\"" + QString(ip) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(ip) + ":" + QString::number(port) + "</font></a>]");
}
SOCKET eNobuffSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
shutdown(eNobuffSocket, SD_BOTH);
closesocket(eNobuffSocket);
if (ENOBUFS == eNobuffSocket || ENOMEM == eNobuffSocket) {
stt->doEmitionRedFoundData("Insufficient buffer/memory space. Sleeping for 10 sec...");
Sleep(10000);
}
return -1;
}
else {
@ -259,26 +271,104 @@ int Connector::nConnect(const char* ip, const int port, std::string *buffer,
}
bool portCheck(const char * sDVRIP, int wDVRPort) {
CURL *curl = curl_easy_init();
if (curl != NULL) {
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(curl, CURLOPT_URL, sDVRIP);
curl_easy_setopt(curl, CURLOPT_PORT, wDVRPort);
int proxyPort = std::atoi(gProxyPort);
if (proxyPort > 0 && proxyPort < 65535) curl_easy_setopt(curl, CURLOPT_PROXYPORT, proxyPort);
curl_easy_setopt(curl, CURLOPT_PROXY, gProxyIP);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, gTimeOut);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, gTimeOut);
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
sockaddr_in sa;
sa.sin_family = AF_INET;
sa.sin_port = htons(wDVRPort);
int res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res != CURLE_OK) {
return false;
}
else return true;
}
hostent *host = NULL;
#if defined(WIN32)
if (inet_addr(sDVRIP) != INADDR_NONE) sa.sin_addr.S_un.S_addr = inet_addr(sDVRIP);
else if (host = gethostbyname(sDVRIP)) ((unsigned long*)&sa.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
#else
if (inet_addr(sDVRIP) != INADDR_NONE) sa.sin_addr.s_addr = inet_addr(sDVRIP);
else if (host = gethostbyname(sDVRIP)) ((unsigned long*)&sa.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
#endif
else return false;
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == INVALID_SOCKET) return -1;
else if (ENOBUFS == sock || ENOMEM == sock) {
stt->doEmitionRedFoundData("Insufficient buffer/memory space. Sleeping for 10 sec...");
return -1;
}
struct linger linger = { 1, gTimeOut };
setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char *)&linger, sizeof(linger));
int res = connect(sock, (sockaddr*)&sa, sizeof(sa));
shutdown(sock, SD_BOTH);
closesocket(sock);
if (res == SOCKET_ERROR) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Port check failed - SOCKET_ERROR. [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
}
return false;
}
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Port check succeeded (curl_code: " + QString::number(res) + ") [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
}
return true;
}
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Port check failed - unknown socket error. [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
}
return false;
//CURL *curl = curl_easy_init();
//if (curl != NULL) {
// curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
// curl_easy_setopt(curl, CURLOPT_URL, sDVRIP);
// curl_easy_setopt(curl, CURLOPT_PORT, wDVRPort);
// int proxyPort = std::atoi(gProxyPort);
// if (proxyPort > 0 && proxyPort < 65535) curl_easy_setopt(curl, CURLOPT_PROXYPORT, proxyPort);
// curl_easy_setopt(curl, CURLOPT_PROXY, gProxyIP);
// curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, gTimeOut);
// curl_easy_setopt(curl, CURLOPT_TIMEOUT, gTimeOut);
// //curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); //DO_NOT_USE. Windows XP - returns CURLE_OK even if port is closed.
// int res = curl_easy_perform(curl);
// curl_easy_cleanup(curl);
// if (res != CURLE_OK) {
// if (gNegDebugMode)
// {
// stt->doEmitionDebugFoundData("Port check failed (curl_code: " + QString::number(res) + ") [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
// }
// SOCKET eNobuffSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
// shutdown(eNobuffSocket, SD_BOTH);
// closesocket(eNobuffSocket);
// if (ENOBUFS == eNobuffSocket || ENOMEM == eNobuffSocket) {
// stt->doEmitionRedFoundData("Insufficient buffer/memory space. Sleeping for 10 sec...");
// Sleep(10000);
// }
// return false;
// }
// else {
// if (gNegDebugMode)
// {
// stt->doEmitionDebugFoundData("Port check succeeded (curl_code: " + QString::number(res) + ") [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
// }
// return true;
// }
//}
//else {
// if (gNegDebugMode)
// {
// stt->doEmitionDebugFoundData("Port check failed - curl_easy_init() error. [<a href=\"" + QString(sDVRIP) + ":" + QString::number(wDVRPort) +
// "/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(wDVRPort) + "</font></a>]");
// }
// return false;
//}
}
int Connector::connectToPort(char* ip, int port)
{

View File

@ -80,10 +80,24 @@ bool HikVis::checkHikk(const char * sDVRIP, int port) {
if (inet_addr(sDVRIP) != INADDR_NONE) sa.sin_addr.s_addr = inet_addr(sDVRIP);
else if (host = gethostbyname(sDVRIP)) ((unsigned long*)&sa.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
#endif
else return false;
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("inet_addr error - iVMS check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == INVALID_SOCKET) return false;
if (sock == INVALID_SOCKET) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Socket error - iVMS check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
struct linger linger = { 1, gTimeOut };
setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char *)&linger, sizeof(linger));
@ -104,12 +118,31 @@ bool HikVis::checkHikk(const char * sDVRIP, int port) {
shutdown(sock, SD_BOTH);
closesocket(sock);
if (buff[3] == 0x10) return true;
else return false;
if (buff[3] == 0x10) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("iVMS check succeeded [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return true;
}
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("iVMS check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
}
shutdown(sock, SD_BOTH);
closesocket(sock);
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Unknown error - iVMS check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
@ -126,10 +159,24 @@ bool HikVis::checkRVI(const char * sDVRIP, int port) {
if (inet_addr(sDVRIP) != INADDR_NONE) sa.sin_addr.s_addr = inet_addr(sDVRIP);
else if (host = gethostbyname(sDVRIP)) ((unsigned long*)&sa.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
#endif
else return false;
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("inet_addr error - RVI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == INVALID_SOCKET) return false;
if (sock == INVALID_SOCKET) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Socket error - RVI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
struct linger linger = { 1, gTimeOut };
setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char *)&linger, sizeof(linger));
@ -150,12 +197,31 @@ bool HikVis::checkRVI(const char * sDVRIP, int port) {
shutdown(sock, SD_BOTH);
closesocket(sock);
if (buff[0] == -80) return true;
else return false;
if (buff[0] == -80) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("RVI check succeeded [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return true;
}
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("RVI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
}
shutdown(sock, SD_BOTH);
closesocket(sock);
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Unknown error - RVI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
@ -172,10 +238,24 @@ bool HikVis::checkSAFARI(const char * sDVRIP, int port) {
if (inet_addr(sDVRIP) != INADDR_NONE) sa.sin_addr.s_addr = inet_addr(sDVRIP);
else if (host = gethostbyname(sDVRIP)) ((unsigned long*)&sa.sin_addr)[0] = ((unsigned long**)host->h_addr_list)[0][0];
#endif
else return false;
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("inet_addr error - SAFARI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == INVALID_SOCKET) return false;
if (sock == INVALID_SOCKET) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Socket error - SAFARI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
struct linger linger = { 1, gTimeOut };
setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char *)&linger, sizeof(linger));
@ -197,15 +277,39 @@ bool HikVis::checkSAFARI(const char * sDVRIP, int port) {
closesocket(sock);
if (buff[0] != '\0') {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("SAFARI check succeeded [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return true;
}
if (buff[0] == 8) return true;
else return false;
if (buff[0] == 8) {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("SAFARI check succeeded [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return true;
}
else {
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("SAFARI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}
}
shutdown(sock, SD_BOTH);
closesocket(sock);
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Unknown error - SAFARI check failed [<a href=\"" + QString(sDVRIP) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(sDVRIP) + ":" + QString::number(port) + "</font></a>]");
}
return false;
}

View File

@ -1381,10 +1381,10 @@ void MainStarter::runAuxiliaryThreads() {
std::thread lpThread(FileUpdater::updateLists);
lpThread.detach();
}
if (!trackerRunning) {
std::thread trackerThread(_tracker);
trackerThread.detach();
}
//if (!trackerRunning) {
// std::thread trackerThread(_tracker);
// trackerThread.detach();
//}
if (!ipPerSecTimer) {
std::thread timerThread(_IPPerSecTimer);
timerThread.detach();

View File

@ -233,7 +233,7 @@ bool isNegative(const std::string *buff, const char *ip, int port, const char *c
FileUpdater::cv.wait(FileUpdater::lk, []{return FileUpdater::ready; });
if (!globalScanFlag) return true;
if (Utils::ustrstr(std::string(codedStr.toLocal8Bit().data()), negEntry) != -1){
if (Utils::ustrstr(std::string(codedStr.toLocal8Bit().data()), negEntry) != -1) {
if (gNegDebugMode)
{
QTextCodec *nCodec = QTextCodec::codecForName("Windows-1251");
@ -282,6 +282,11 @@ int globalSearchPrnt(const std::string *buff)
{
//if(gNegDebugMode) stt->doEmitionDebugFoundData("Printer detected.");
if (gNegDebugMode)
{
QTextCodec *nCodec = QTextCodec::codecForName("Windows-1251");
stt->doEmitionDebugFoundData("Printer ignored");
}
return -1;
};
@ -294,19 +299,43 @@ int sharedDetector(const char * ip, int port, const std::string *buffcpy, const
if (HikVis::checkSAFARI(ip, port)) return 6; //Safari CCTV
else if (HikVis::checkHikk(ip, port)) return 4; //Hikkvision iVMS
else if (HikVis::checkRVI(ip, port)) return 5; //RVI
else return -1;
else
{
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Safari CCTV check failed - ignoring [<a href=\"" + QString(ip) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(ip) + ":" + QString::number(port) + "</font></a>]");
}
return -1;
}
}
else if(port == 8000) {
if (HikVis::checkHikk(ip, port)) return 4; //Hikkvision iVMS
else if (HikVis::checkRVI(ip, port)) return 5; //RVI
//else if (HikVis::checkSAFARI(ip, port)) return 6; //Safari CCTV
else return -1;
else
{
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("Hikkvision iVMS check failed - ignoring [<a href=\"" + QString(ip) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(ip) + ":" + QString::number(port) + "</font></a>]");
}
return -1;
}
}
else if (port == 37777) {
if (HikVis::checkRVI(ip, port)) return 5; //RVI
else if(HikVis::checkHikk(ip, port)) return 4; //Hikkvision iVMS
else if (HikVis::checkSAFARI(ip, port)) return 6; //Safari CCTV
else return -1;
else
{
if (gNegDebugMode)
{
stt->doEmitionDebugFoundData("RVI check failed - ignoring [<a href=\"" + QString(ip) + ":" + QString::number(port) +
"/\"><font color=\"#0084ff\">" + QString(ip) + ":" + QString::number(port) + "</font></a>]");
}
return -1;
}
}
}
@ -2831,8 +2860,8 @@ void parseFlag(int flag, char* ip, int port, int size, const std::string &header
lopaStr lps = hv.HVLobby(ip, port);
if (strstr(lps.login, "UNKNOWN") == NULL && strlen(lps.other) == 0)
{
_specFillerBA(ip, port, "[Hikvision IVMS].", lps.login, lps.pass, 0);
fillGlobalLogData(ip, port, std::to_string(size).c_str(), "[Hikvision IVMS] ().",
_specFillerBA(ip, port, "[Hikvision IVMS]", lps.login, lps.pass, 0);
fillGlobalLogData(ip, port, std::to_string(size).c_str(), "[Hikvision IVMS] ()",
lps.login, lps.pass, "[Hikvision IVMS]", "UTF-8", "Basic Authorization");
while (hikkaStop) Sleep(10);
@ -2865,8 +2894,8 @@ void parseFlag(int flag, char* ip, int port, int size, const std::string &header
lopaStr lps = hv.RVILobby(ip, port);
if (strstr(lps.login, "UNKNOWN") == NULL && strlen(lps.other) == 0)
{
_specFillerBA(ip, port, "[RVI].", lps.login, lps.pass, 0);
fillGlobalLogData(ip, port, std::to_string(size).c_str(), "[RVI] ().",
_specFillerBA(ip, port, "[RVI]", lps.login, lps.pass, 0);
fillGlobalLogData(ip, port, std::to_string(size).c_str(), "[RVI] ()",
lps.login, lps.pass, "[RVI]", "UTF-8", "Basic Authorization");
while (rviStop) Sleep(10);