Skip to content

Instantly share code, notes, and snippets.

@deckerego
Created May 7, 2015 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deckerego/3e00f9295a88aa38abf6 to your computer and use it in GitHub Desktop.
Save deckerego/3e00f9295a88aa38abf6 to your computer and use it in GitHub Desktop.
Send your current IP address to Slack
import argparse
config_values = {
'slack_api_token': 'toooooken',
'slack_channel': '#channel'
}
class Configuration(object):
def __init__(self):
parser = argparse.ArgumentParser()
args, _ = parser.parse_known_args()
def get(self, name):
return config_values.get(name)
configuration = Configuration()
import logging
import socket
from slacker import Slacker
from config import configuration
logger = logging.getLogger('slack')
class Slack(object):
def __init__(self, printer):
self.slack = Slacker(configuration.get('slack_api_token'))
self.channel = configuration.get('slack_channel')
def sendAddr(self, message):
test_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
test_sock.connect(("8.8.8.8", 53))
self.hostname = test_sock.getsockname()[0]
self.slack.chat.post_message(self.channel, "Current Host: %s" % self.hostname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment