Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. var blShortReply = make([]string, 0, 10)
  2. if !strings.HasPrefix(event.Message, "!lookup") {
  3. return // We weren't given a !lookup command
  4. }
  5.  
  6. StringMessageSplit := strings.Split(event.Message, " ")
  7. if len(StringMessageSplit) < 1 {
  8. return // We weren't given anything after the !lookup command
  9. }
  10.  
  11. IPToCheck := net.ParseIP(StringMessageSplit[1]).To4() // Only handles IPv4, currently.
  12. if IPToCheck == nil {
  13. ircbot.writesocket <- fmt.Sprintf("PRIVMSG %s :Wasn't given a valid IP, %s\r\n", event.Arguments[0], StringMessageSplit[1])
  14. return // We weren't given a valid IP
  15. }
  16.  
  17. /* If we have made it to this point we have a valid IP and should begin doing blacklist lookups. */
  18. StringIP := IPToCheck.String() // Turn the IP into a String for processing
  19. StringIPSplit := strings.Split(StringIP, ".") // Split the IP by .
  20. DroneBL := fmt.Sprintf("%s.%s.%s.%s.dnsbl.dronebl.org", StringIPSplit[3], StringIPSplit[2], StringIPSplit[1], StringIPSplit[0])
  21. DroneBLReply, _ := net.LookupHost(DroneBL)
  22.  
  23. ircbot.writesocket <- fmt.Sprintf("PRIVMSG %s :Looking up: %s\r\n", event.Arguments[0], StringIP)
  24.  
  25. if len(DroneBLReply) == 0 {
  26. ircbot.writesocket <- fmt.Sprintf("PRIVMSG %s :No listings for %s\r\n", event.Arguments[0], StringIP)
  27. return // Not listed in DroneBL!
  28. }
  29.  
  30. /* Loop over all of the replies and append the last octet to blShortReply */
  31. for key := range DroneBLReply {
  32. blFullReply := strings.Split(DroneBLReply[key], ".")
  33. blShortReply = append(blShortReply, blFullReply[3])
  34. }
  35.  
  36. /* IP was listed in DroneBL, print the listings to the channel. */
  37. ircbot.writesocket <- fmt.Sprintf("PRIVMSG %s :dnsbl return: %s\r\n", event.Arguments[0], blShortReply)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement