Skip to content

Commit

Permalink
added ip lookup functionality for fun... just yet another module!
Browse files Browse the repository at this point in the history
  • Loading branch information
c650 committed Dec 27, 2016
1 parent fa28612 commit 13f9d1b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/include/iplookup.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef _IPLOOKUP_H
#define _IPLOOKUP_H

#include "./json.hpp"

namespace IPLookup {

std::string do_lookup(const std::string& host);

};

#endif
22 changes: 22 additions & 0 deletions src/iplookup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "./include/iplookup.hpp"
#include "./include/json.hpp"
#include "./include/http.hpp"

namespace IPLookup {

static void do_lookup_internal(const std::string& host, nlohmann::json& result) {
std::string response = "";
MyHTTP::get("http://freegeoip.net/json/" + host, response);
result = nlohmann::json::parse(response);
}

std::string do_lookup(const std::string& host) {

nlohmann::json result;
do_lookup_internal(host,result);

return "Location: " + result["city"].get<std::string>() + ", " + result["region_code"].get<std::string>() + ", "
+ result["country_name"].get<std::string>();
}

};
7 changes: 7 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "./include/json.hpp" /* from https://github.com/nlohmann/json */
#include "./include/googler.hpp"
#include "./include/babbler.hpp"
#include "./include/iplookup.hpp"

#include "./include/bot.hpp"
#include "./include/packet.hpp"
Expand Down Expand Up @@ -76,6 +77,12 @@ int main(void) {
packet.reply( babbler.sample() );
}, "produces random technobabble");

b.on_privmsg("@iplookup ", [](const IRC::Packet& packet){

packet.reply( IPLookup::do_lookup( packet.content.substr( 10 ) ) );

}, "looks up a specified IP.", REQUIRES_ADMIN_PERMS);

b.on_privmsg("@kick ", [](const IRC::Packet& packet){
packet.owner->kick(packet.channel, packet.content.substr(6));
}, "kicks specified user.", REQUIRES_ADMIN_PERMS);
Expand Down

0 comments on commit 13f9d1b

Please sign in to comment.