Помощь - Поиск - Пользователи - Календарь
Полная версия: Получить содержимое страницы
UoKit.com Форумы > Кликер > UO Pilot
cirus
Пример1
Код
--lua
local ffi = require("ffi")
local inet = ffi.load('Wininet.dll')

local INTERNET_OPEN_TYPE_PRECONFIG = 0
local INTERNET_DEFAULT_HTTPS_PORT = 443
local INTERNET_SERVICE_HTTP = 3
local INTERNET_FLAG_SECURE = 8388608
local INTERNET_FLAG_NO_CACHE_WRITE = 67108864
ffi.cdef[[
int InternetOpenA(const char* lpszAgent, unsigned long  dwAccessType, const char* lpszProxy, const char* lpszProxyBypass, unsigned long dwFlags);
bool InternetCloseHandle(int hInternet);
int InternetConnectA(int hInternet, const char* lpszServerName, unsigned short nServerPort, const char* lpszUserName,
  const char* lpszPassword, unsigned long dwService, unsigned long dwFlags,unsigned long dwContext);
int HttpOpenRequestA(int hConnect, const char* lpszVerb, const char* lpszObjectName, const char* lpszVersion,
  const char* lpszReferrer, const char* lplpszAcceptTypes, unsigned long dwFlags, unsigned long dwContext);
bool HttpSendRequestA(int hRequest, const char* lpszHeaders, unsigned long dwHeadersLength, const char* lpOptional, unsigned long dwOptionalLength);
bool InternetReadFile(int hFile, char* lpBuffer, unsigned long dwNumberOfBytesToRead, unsigned long* lpdwNumberOfBytesRead);
]]

function http(Verb, ServerName, ObjectName)
    local buf = ffi.new('char[9999]')
    local dwBytesRead = ffi.new('unsigned long[1]')
    local hInternet = inet.InternetOpenA("Mozilla", INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0)
    if hInternet then
        local hConnect = inet.InternetConnectA(hInternet, ServerName, INTERNET_DEFAULT_HTTPS_PORT, nil, nil, INTERNET_SERVICE_HTTP, 0, 0)
        if hConnect then
            local hRequest = inet.HttpOpenRequestA(hConnect, Verb, ObjectName, nil, nil, nil, INTERNET_FLAG_SECURE + INTERNET_FLAG_NO_CACHE_WRITE, 0)
            if hRequest then
                inet.HttpSendRequestA(hRequest, '', 0, '', 0)
                local fr=''
                while inet.InternetReadFile(hRequest, buf, ffi.sizeof(buf)-1, dwBytesRead) do
                    if dwBytesRead[0] == 0 then break end
                    fr = fr .. ffi.string(buf, dwBytesRead[0])
                end
                inet.InternetCloseHandle(hRequest)
                return fr
            end
            inet.InternetCloseHandle(hConnect)
        end
        local close = inet.InternetCloseHandle(hInternet)
    end
end

log 'clear' log 'mode compact'

local s = http('POST', 'forum.uokit.com', 'index.php')   -- отправка запроса
-- в переменной s содержится код страницы forum.uokit.com/index.php

local guest, user, hidden = s:match('%<b%>(%d+)%<%/b%> гостей, %<b%>(%d+)%<%/b%> пользователей %<b%>(%d+)%<%/b%> скрытых пользователей')
log('На форуме сейчас:\r\n', guest, 'гостей, ', user, ' пользователей, ', hidden, ' скрытых пользователей\r\n')
log('Список пользователей:')
for name_user in s:gmatch('title=.%d+:%d+.-([^%>]-)%<%/') do
    log(name_user)
end

Пример2
Код
--lua
local ffi = require("ffi")
local inet = ffi.load('Wininet.dll')
local shell = ffi.load('Shell32.dll')
ffi.cdef[[
int InternetOpenA(const char* lpszAgent, unsigned long  dwAccessType, const char* lpszProxy, const char* lpszProxyBypass, unsigned long dwFlags);
bool InternetCloseHandle(int hInternet);
int InternetConnectA(int hInternet, const char* lpszServerName, unsigned short nServerPort, const char* lpszUserName,
  const char* lpszPassword, unsigned long dwService, unsigned long dwFlags,unsigned long dwContext);
int HttpOpenRequestA(int hConnect, const char* lpszVerb, const char* lpszObjectName, const char* lpszVersion,
  const char* lpszReferrer, const char* lplpszAcceptTypes, unsigned long dwFlags, unsigned long dwContext);
bool HttpSendRequestA(int hRequest, const char* lpszHeaders, unsigned long dwHeadersLength, const char* lpOptional, unsigned long dwOptionalLength);
bool InternetReadFile(int hFile, char* lpBuffer, unsigned long dwNumberOfBytesToRead, unsigned long* lpdwNumberOfBytesRead);
]]
local INTERNET_OPEN_TYPE_PRECONFIG = 0
local INTERNET_DEFAULT_HTTPS_PORT = 443
local INTERNET_SERVICE_HTTP = 3
local INTERNET_FLAG_SECURE = 8388608
local INTERNET_FLAG_NO_CACHE_WRITE = 67108864

ffi.cdef[[int ShellExecuteA(int hwnd, const char* lpOperation, const char* lpFile, const char* lpParameters, const char* lpDirectory, int nShowCmd);]]
local SW_SHOW = 5

function http(Verb, ServerName, ObjectName)
    local buf = ffi.new('char[9999]')
    local dwBytesRead = ffi.new('unsigned long[1]')
    local hInternet = inet.InternetOpenA("Mozilla", INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0)
    if hInternet then
        local hConnect = inet.InternetConnectA(hInternet, ServerName, INTERNET_DEFAULT_HTTPS_PORT, nil, nil, INTERNET_SERVICE_HTTP, 0, 0)
        if hConnect then
            local hRequest = inet.HttpOpenRequestA(hConnect, Verb, ObjectName, nil, nil, nil, INTERNET_FLAG_SECURE + INTERNET_FLAG_NO_CACHE_WRITE, 0)
            if hRequest then
                inet.HttpSendRequestA(hRequest, '', 0, '', 0)
                local fr=''
                while inet.InternetReadFile(hRequest, buf, ffi.sizeof(buf)-1, dwBytesRead) do
                    if dwBytesRead[0] == 0 then break end
                    fr = fr .. ffi.string(buf, dwBytesRead[0])
                end
                inet.InternetCloseHandle(hRequest)
                return fr
            end
            inet.InternetCloseHandle(hConnect)
        end
        local close = inet.InternetCloseHandle(hInternet)
    end
    return nil
end

log 'clear' log 'mode compact'
local name_function = 'CreateWindowExA'
-- получить содержимое страницы  https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowexa
local s = http('POST', 'docs.microsoft.com', [[en-us/windows/win32/api/winuser/nf-winuser-]] .. name_function)
if s then
    local file = io.open([[C:\content.txt]], 'wb')
    if file then
        file:write(s)
        file:close()
        shell.ShellExecuteA(0, 'open', [[C:\content.txt]], '', '', SW_SHOW)
    end

    -- найти текст между <pre><code class="lang-cpp"> и </code></pre>
    local parameters = s:match('%<pre%>%<code class%=%"lang%-cpp%"%>(.-)%<%/code%>%<%/pre%>')
    if parameters then
        log (parameters)
    end
end

Пример3
Код
--lua
local ffi = require("ffi")
local inet = ffi.load('Wininet.dll')

local INTERNET_OPEN_TYPE_PRECONFIG = 0
local INTERNET_DEFAULT_HTTPS_PORT = 443
local INTERNET_SERVICE_HTTP = 3
local INTERNET_FLAG_SECURE = 8388608
local INTERNET_FLAG_NO_CACHE_WRITE = 67108864
ffi.cdef[[
int InternetOpenA(const char* lpszAgent, unsigned long  dwAccessType, const char* lpszProxy, const char* lpszProxyBypass, unsigned long dwFlags);
bool InternetCloseHandle(int hInternet);
int InternetConnectA(int hInternet, const char* lpszServerName, unsigned short nServerPort, const char* lpszUserName,
  const char* lpszPassword, unsigned long dwService, unsigned long dwFlags,unsigned long dwContext);
int HttpOpenRequestA(int hConnect, const char* lpszVerb, const char* lpszObjectName, const char* lpszVersion,
  const char* lpszReferrer, const char* lplpszAcceptTypes, unsigned long dwFlags, unsigned long dwContext);
bool HttpSendRequestA(int hRequest, const char* lpszHeaders, unsigned long dwHeadersLength, const char* lpOptional, unsigned long dwOptionalLength);
bool InternetReadFile(int hFile, char* lpBuffer, unsigned long dwNumberOfBytesToRead, unsigned long* lpdwNumberOfBytesRead);
]]

function http(Verb, ServerName, ObjectName)
    local buf = ffi.new('char[9999]')
    local dwBytesRead = ffi.new('unsigned long[1]')
    local hInternet = inet.InternetOpenA("Mozilla", INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0)
    if hInternet then
        local hConnect = inet.InternetConnectA(hInternet, ServerName, INTERNET_DEFAULT_HTTPS_PORT, nil, nil, INTERNET_SERVICE_HTTP, 0, 0)
        if hConnect then
            local hRequest = inet.HttpOpenRequestA(hConnect, Verb, ObjectName, nil, nil, nil, INTERNET_FLAG_SECURE + INTERNET_FLAG_NO_CACHE_WRITE, 0)
            if hRequest then
                inet.HttpSendRequestA(hRequest, '', 0, '', 0)
                local fr=''
                while inet.InternetReadFile(hRequest, buf, ffi.sizeof(buf)-1, dwBytesRead) do
                    if dwBytesRead[0] == 0 then break end
                    fr = fr .. ffi.string(buf, dwBytesRead[0])
                end
                inet.InternetCloseHandle(hRequest)
                return fr
            end
            inet.InternetCloseHandle(hConnect)
        end
        local close = inet.InternetCloseHandle(hInternet)
    end
end

log 'clear' log 'mode compact'
local s = http('GET', 'api.ipify.org', '')   -- отправка запроса
log (s)
s = http('GET', 'api.ipify.org', '?format=json')   -- отправка запроса
log (s)
Fors1k
thumbsup.gif
DarkMaster
Сильно. В юзерагенте что отсылает?
cirus
Цитата
В юзерагенте что отсылает?

В данном случае Mozilla. Можно вписать что нужно.
В HttpSendRequestA можно указать заголовок и нужные данные.

neves
How to send request to given IP instead of domain name?

for example:
Код
local s = http('GET', 'mail.ru', ' ')
log (s)

This works and prints the whole html of mail.ru.
Код
local s = http('GET', '94.100.180.70', ' ')
log (s)

This sends request to the IP address of mail.ru and doesn't works.
This isn't good example, but you can understand what am I trying to say.
Server IP may be something like this too: 54.12.142.102:3333, still doesn't works.
Edit:
Example url: http://97.77.172.242:8088/
Fors1k
Цитата(neves @ 29.10.2020, 3:04) *
Код
local s = http('GET', '94.100.180.70', ' ')
log (s)
This sends request to the IP address of mail.ru and doesn't works.

This works:
Код
log "clear";log "mode compact";require"luaposh"

ip = "94.100.180.70"
RealAddress=PScode('return',{[[$return=[net.dns]::GetHostByAddress($input).hostname]]},ip)
local s = http('GET', RealAddress, ' ')
log (s)

Цитата(neves @ 29.10.2020, 3:04) *

This address is unavailable. Give another good address to test.
Fors1k
Цитата

Никак не могу получить содержимое этой страницы(именно эта ссылка как пример).
Все время выдает контент страницы капчи. Еще обнаружил, что со всех браузеров ссылка открывается норм, а с IE сразу выводит на капчу.
Есть идеи как обойти это?
DarkMaster
Берешь Charles, смотришь разницу в траффике между скриптом/ie/другими браузерами. Добавляешь/меняешь заголовки до достижения нужного результата.
Это текстовая версия — только основной контент. Для просмотра полной версии этой страницы, пожалуйста, нажмите сюда.
Русская версия Invision Power Board © 2001-2024 Invision Power Services, Inc.