Версия для печати темы

Нажмите сюда для просмотра этой темы в обычном формате

UoKit.com Форумы _ UO Pilot _ Получить содержимое страницы

Автор: cirus 13.10.2020, 13:13

Пример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 13.10.2020, 15:48

thumbsup.gif

Автор: DarkMaster 15.10.2020, 2:46

Сильно. В юзерагенте что отсылает?

Автор: cirus 15.10.2020, 3:05

Цитата
В юзерагенте что отсылает?

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


Автор: neves 29.10.2020, 3:04

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 29.10.2020, 20:37

Цитата(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) *

Example url: http://97.77.172.242:8088/

This address is unavailable. Give another good address to test.

Автор: Fors1k 19.12.2020, 22:13

Цитата
https://kad.arbitr.ru/Card/29a71f9b-eee5-4836-8f20-7b4810b0f8cd

Никак не могу получить содержимое этой страницы(именно эта ссылка как пример).
Все время выдает контент страницы капчи. Еще обнаружил, что со всех браузеров ссылка открывается норм, а с IE сразу выводит на капчу.
Есть идеи как обойти это?

Автор: DarkMaster 20.12.2020, 0:56

Берешь Charles, смотришь разницу в траффике между скриптом/ie/другими браузерами. Добавляешь/меняешь заголовки до достижения нужного результата.

Русская версия Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)