mirror of
https://github.com/arnaucube/goNmapTelegramBot.git
synced 2026-02-07 03:16:39 +01:00
works
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
temp
|
||||
*.json
|
||||
8
README.md
Normal file
8
README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# goNmapTelegramBot
|
||||
|
||||
This is a simple telegram bot, that gets an ip, performs a nmap port scan, and returns the result to the telegram user.
|
||||
|
||||
Warning: is not recommended to leave the Bot running, a possible attack to the Bot (and the server where is the Bot running) could be insect command lines outside the nmap
|
||||
|
||||
|
||||

|
||||
BIN
goNmapTelegramBot
Executable file
BIN
goNmapTelegramBot
Executable file
Binary file not shown.
21
main.go
Normal file
21
main.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func checkIp(text string) bool {
|
||||
if len(strings.Split(text, ".")) != 4 {
|
||||
return false
|
||||
}
|
||||
if len(strings.Split(text, "")) > 16 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func main() {
|
||||
readConfig()
|
||||
telegramBot()
|
||||
}
|
||||
16
nmap.go
Normal file
16
nmap.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func nmap(ip string) string {
|
||||
out, err := exec.Command("nmap", "-T4", "F", ip).Output()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
fmt.Println(string(out))
|
||||
return string(out)
|
||||
}
|
||||
25
readConfig.go
Normal file
25
readConfig.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
//Config stores the data from json twitterConfig.json file
|
||||
type Config struct {
|
||||
TelegramBotToken string `json:"telegramBotToken"`
|
||||
}
|
||||
|
||||
var config Config
|
||||
|
||||
func readConfig() {
|
||||
file, e := ioutil.ReadFile("config.json")
|
||||
if e != nil {
|
||||
fmt.Println("error:", e)
|
||||
}
|
||||
content := string(file)
|
||||
json.Unmarshal([]byte(content), &config)
|
||||
fmt.Println("config.json read comlete, Telegram bot ready")
|
||||
|
||||
}
|
||||
BIN
screenrecording1.gif
Normal file
BIN
screenrecording1.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 MiB |
49
telegramBot.go
Normal file
49
telegramBot.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
)
|
||||
|
||||
func telegramBot() {
|
||||
bot, err := tgbotapi.NewBotAPI(config.TelegramBotToken)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
//bot.Debug = true
|
||||
//log.Printf("Authorized on account %s", bot.Self.UserName)
|
||||
|
||||
u := tgbotapi.NewUpdate(0)
|
||||
u.Timeout = 60
|
||||
|
||||
updates, err := bot.GetUpdatesChan(u)
|
||||
|
||||
for update := range updates {
|
||||
if update.Message == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
//log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
|
||||
fmt.Println("new ip to scan: " + update.Message.Text)
|
||||
var result string
|
||||
ok := checkIp(update.Message.Text)
|
||||
if update.Message.Text == "/start" {
|
||||
result = "welcome to nmap telegram bot, written in Go lang"
|
||||
} else {
|
||||
|
||||
if ok {
|
||||
result = nmap(update.Message.Text)
|
||||
} else {
|
||||
result = "ip not valid"
|
||||
}
|
||||
}
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, result)
|
||||
msg.ReplyToMessageID = update.Message.MessageID
|
||||
|
||||
bot.Send(msg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user