2025-02-21 18:49:58 +08:00
|
|
|
|
package method
|
|
|
|
|
|
|
|
|
|
import (
|
2025-03-04 17:40:37 +08:00
|
|
|
|
"bufio"
|
2025-02-21 18:49:58 +08:00
|
|
|
|
"dt_automate/tool"
|
2025-02-26 23:24:36 +08:00
|
|
|
|
"fmt"
|
2025-02-21 18:49:58 +08:00
|
|
|
|
"log"
|
2025-03-04 17:40:37 +08:00
|
|
|
|
"os"
|
2025-02-21 18:49:58 +08:00
|
|
|
|
|
|
|
|
|
"github.com/playwright-community/playwright-go"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func HW_TSGZ() {
|
|
|
|
|
// 启动 Playwright
|
|
|
|
|
pw, err := playwright.Run()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not start Playwright: %v", err)
|
|
|
|
|
}
|
|
|
|
|
defer pw.Stop()
|
|
|
|
|
|
|
|
|
|
// 启动浏览器(Chromium)
|
|
|
|
|
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
|
|
|
|
|
Headless: playwright.Bool(false), // 设置为 false 以显示浏览器界面
|
|
|
|
|
Args: []string{
|
|
|
|
|
"--ignore-certificate-errors", // 忽略证书错误[^28^][^29^]
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not launch browser: %v", err)
|
|
|
|
|
}
|
|
|
|
|
defer browser.Close()
|
|
|
|
|
|
|
|
|
|
// 创建一个新页面
|
|
|
|
|
page, err := browser.NewPage()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not create page: %v", err)
|
|
|
|
|
}
|
|
|
|
|
// 设置浏览器窗口大小
|
|
|
|
|
err = page.SetViewportSize(1920, 1080) // 宽度为 1200px,高度为 800px
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("无法设置浏览器窗口大小: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 导航到指定网址
|
2025-02-27 18:37:03 +08:00
|
|
|
|
_, err = page.Goto("https://11.2.65.21/", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateDomcontentloaded})
|
2025-02-21 18:49:58 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not go to the page: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
page.WaitForTimeout(2000)
|
|
|
|
|
page.Locator(`.verification-item .el-image`).Screenshot(playwright.LocatorScreenshotOptions{
|
|
|
|
|
Path: playwright.String("img/capt.png"),
|
|
|
|
|
})
|
|
|
|
|
a := page.Locator(`.el-input__inner`)
|
2025-02-26 23:24:36 +08:00
|
|
|
|
// result := wtch_ocr.OcrDefault("img/capt.png")
|
|
|
|
|
// if len(result.OcrResponse[0].Text) == 4 {
|
|
|
|
|
// log.Println("读取验证码:", result.OcrResponse[0].Text)
|
|
|
|
|
// a.Nth(2).Fill(result.OcrResponse[0].Text)
|
|
|
|
|
// } else {
|
|
|
|
|
// page.WaitForTimeout(500)
|
|
|
|
|
// page.Locator(".verification-item .el-image .el-image__inner").Click()
|
|
|
|
|
// }
|
2025-02-21 18:49:58 +08:00
|
|
|
|
|
|
|
|
|
// Screenshot(playwright.PageScreenshotOptions{})
|
|
|
|
|
// (playwright.PageScreenshotOptions{
|
|
|
|
|
// Path: playwright.String("img/capg.png"),
|
|
|
|
|
// FullPage: playwright.Bool(true),
|
|
|
|
|
// })
|
|
|
|
|
//输入
|
|
|
|
|
a.Nth(0).Fill("admin")
|
|
|
|
|
page.WaitForTimeout(500)
|
|
|
|
|
a.Nth(1).Fill("BWySN~QjrlwFsA)@#h")
|
2025-03-04 17:40:37 +08:00
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
2025-02-26 23:24:36 +08:00
|
|
|
|
fmt.Print("请输入验证码:")
|
2025-03-04 17:40:37 +08:00
|
|
|
|
input, _ := reader.ReadString('\n')
|
|
|
|
|
a.Nth(2).Fill(input)
|
2025-02-21 18:49:58 +08:00
|
|
|
|
page.WaitForTimeout(500)
|
|
|
|
|
//点击同意
|
|
|
|
|
if err := page.Locator(`.el-checkbox__inner`).Click(); err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
|
|
|
|
//登录
|
|
|
|
|
page.WaitForTimeout(1000)
|
|
|
|
|
if err := page.Locator(`.el-button.el-button--primary.el-button--large.login-button`).Click(); err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
|
|
|
|
page.WaitForTimeout(500)
|
|
|
|
|
_, err = page.Goto("https://11.2.65.21/#/threatCenter/asset")
|
|
|
|
|
page.WaitForTimeout(1000)
|
|
|
|
|
page.Evaluate(`
|
|
|
|
|
const now = new Date();
|
|
|
|
|
const year = now.getFullYear();
|
|
|
|
|
const month = (now.getMonth() + 1).toString().padStart(2, '0');
|
|
|
|
|
const day = now.getDate().toString().padStart(2, '0');
|
|
|
|
|
const hours = now.getHours().toString().padStart(2, '0');
|
|
|
|
|
const minutes = now.getMinutes().toString().padStart(2, '0');
|
|
|
|
|
const seconds = now.getSeconds().toString().padStart(2, '0');
|
|
|
|
|
const timestamp = year+"-"+month+"-"+day +" "+ hours+":"+minutes+":"+seconds;
|
|
|
|
|
const div = document.createElement('div');
|
|
|
|
|
div.style.position = 'fixed';
|
|
|
|
|
div.style.bottom = '10px';
|
|
|
|
|
div.style.right = '10px';
|
|
|
|
|
div.style.color = 'white';
|
|
|
|
|
div.style.backgroundColor = 'black';
|
|
|
|
|
div.style.padding = '5px';
|
|
|
|
|
div.style.borderRadius = '5px';
|
|
|
|
|
div.textContent = timestamp;
|
|
|
|
|
document.body.appendChild(div);
|
|
|
|
|
`, nil)
|
|
|
|
|
page.Locator(`.el-range-input`).Nth(0).Click()
|
|
|
|
|
page.WaitForTimeout(500)
|
|
|
|
|
page.Locator(`.el-picker-panel__shortcut`).Nth(0).Click()
|
|
|
|
|
page.WaitForTimeout(300)
|
|
|
|
|
page.Locator(`.display-inline-flex.align-items-center.justify-content-end.advanced-search-wrapper .el-button.el-button--primary`).Click()
|
|
|
|
|
page.WaitForTimeout(1000)
|
|
|
|
|
tool.Jietu("img/hw_tsgz.png")
|
|
|
|
|
page.WaitForTimeout(2000)
|
|
|
|
|
// 获取页面标题
|
|
|
|
|
title, err := page.Title()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not get title: %v", err)
|
|
|
|
|
}
|
|
|
|
|
log.Printf("Page title is: %s\n", title)
|
|
|
|
|
|
|
|
|
|
// StartBlocker()
|
|
|
|
|
page.WaitForTimeout(5000)
|
|
|
|
|
}
|