You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
970 B

7 years ago
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "gopkg.in/telegram-bot-api.v4"
  6. )
  7. func telegramBot() {
  8. bot, err := tgbotapi.NewBotAPI(config.TelegramBotToken)
  9. if err != nil {
  10. log.Panic(err)
  11. }
  12. //bot.Debug = true
  13. //log.Printf("Authorized on account %s", bot.Self.UserName)
  14. u := tgbotapi.NewUpdate(0)
  15. u.Timeout = 60
  16. updates, err := bot.GetUpdatesChan(u)
  17. for update := range updates {
  18. if update.Message == nil {
  19. continue
  20. }
  21. //log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
  22. fmt.Println("new ip to scan: " + update.Message.Text)
  23. var result string
  24. ok := checkIp(update.Message.Text)
  25. if update.Message.Text == "/start" {
  26. result = "welcome to nmap telegram bot, written in Go lang"
  27. } else {
  28. if ok {
  29. result = nmap(update.Message.Text)
  30. } else {
  31. result = "ip not valid"
  32. }
  33. }
  34. msg := tgbotapi.NewMessage(update.Message.Chat.ID, result)
  35. msg.ReplyToMessageID = update.Message.MessageID
  36. bot.Send(msg)
  37. }
  38. }