#include<string>#include <winsock2.h>#include <ws2tcpip.h>#pragma warning(disable:4996)// 调用格式: SDT_BOOL 端口检测, 命令说明: NULL// 参数<1>: 端口 SDT_SHORT, 参数说明: "检测的端口。"// 参数<2>: [ip地址 SDT_TEXT], 参数说明: "置空则检测本机端口。"static bool check_port_(unsigned short port, const char* ip_address){bool result = false;WSADATA wsa_data;if (WSAStartup(MAKEWORD(2, 2), &wsa_data) == 0){addrinfo hints;ZeroMemory(&hints, sizeof(hints));hints.ai_family = AF_INET;hints.ai_socktype = SOCK_STREAM;hints.ai_protocol = IPPROTO_TCP;addrinfo* addr_result;if (getaddrinfo(ip_address, std::to_string(port).c_str(), &hints, &addr_result) == 0){SOCKET sock = socket(addr_result->ai_family, addr_result->ai_socktype, addr_result->ai_protocol);if (sock != INVALID_SOCKET){if (connect(sock, addr_result->ai_addr, (int)addr_result->ai_addrlen) != SOCKET_ERROR){result = true;}closesocket(sock);}freeaddrinfo(addr_result);}WSACleanup();}return result;}static std::string get_ip_this_a() {WORD wVersionRequested = MAKEWORD(2, 2);WSADATA wsaData;if (WSAStartup(wVersionRequested, &wsaData) != 0)return "";char local[255] = { 0 };gethostname(local, sizeof(local));hostent* ph = gethostbyname(local);if (ph == NULL)return "";in_addr addr;memcpy(&addr, ph->h_addr_list[0], sizeof(in_addr));std::string localIP;localIP.assign(inet_ntoa(addr));WSACleanup();return localIP;}#include "..\include_eapi_header.h"EAPI_EXTERN_C void eapi_CheckPort_54_eapi(PMDATA_INF pRetData, INT nArgCount, PMDATA_INF pArgInf){auto ip = args_to_sdata(pArgInf, 1);pRetData->m_bool = check_port_(pArgInf->m_short, ip.empty() ? get_ip_this_a().c_str() : ip.data());}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。