Exemplo n.º 1
0
def on_connect(client, userdata, flags, rc):
    logger.info("Connected with result code %s" % str(rc))
    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    # client.subscribe("$SYS/#")
    client.subscribe(CLIENT_COMMAND_TOPIC)
    ip_address = ipgetter.myip()
    message = "{}, ip_address: {}".format(TEST_CLIENT_NAME, ip_address)
    client.publish(CLIENT_CONNECTED_TOPIC, message)
Exemplo n.º 2
0
def ipaddr_forecast():

    ipaddr = str(ipgetter.myip())
    reader = geolite2.reader()
    loc = reader.get(ipaddr)
    geolite2.close()

    latlong = str(loc["location"]["latitude"]) + "," + str(
        loc["location"]["longitude"])
    ep = get_endpoint_data(latlong)
    return epdata_to_forecast(ep)
Exemplo n.º 3
0
def encrypt_ip(public_key_path):
    """This function will encrypt a message using the users public key and
    return a set of bytes representing the encrypted IP
    
    :returns: The IP Address of the machine calling this function, encrypted
    :rtype: bytes = b'...' a sequence of octets
    
    """
    # Open the Public Key - the public key of the client computer
    public_key = RSA.importKey(open(public_key_path).read())
    cipher = PKCS1_OAEP.new(public_key)
    message = ipgetter.myip()
    encrypted_message = cipher.encrypt(message.encode("utf-8"))
    
    return encrypted_message
Exemplo n.º 4
0
def send_update_email(host, port, account, password):
    server = smtplib.SMTP_SSL(host, port)
    server.login(account, password)
    try:
        myip = ipgetter.myip()

        # Send to my self
        message = MIMEText(myip, "plain", "utf-8")
        message["From"] = Header("SELF <%s>" % account, "utf-8")
        message["To"] = Header("SELF <%s>" % account, "utf-8")
        message["Subject"] = Header("[EMAIL-DDNS:UPDATE]", "utf-8")

        server.sendmail(account, [account], message.as_string())
    finally:
        server.quit()
Exemplo n.º 5
0
 def show_allips(self, btn):
     myip = ipgetter.myip()
     ip = socket.gethostbyname(socket.gethostname())
     if ip.startswith("127.") and os.name != "nt":
         interfaces = [
             "eth0", "eth1", "eth2", "wlan0", "wlan1", "wifi0", "ath0",
             "ath1", "ppp0"
         ]
         for ifname in interfaces:
             try:
                 ip = get_interface_ip(ifname)
                 btn.data = "Internal IP: " + ip + "\nExternal IP: " + myip
                 btn.visible = True
                 self.display.text = "Internal IP: " + ip + "\nExternal IP: " + myip
             except IOError:
                 pass
Exemplo n.º 6
0
def check_ip(settings):
    """checks if ip has changed"""
    curr_ip = ipgetter.myip()

    if not CURRENT_IP_ADDRESS_PATH.exists():
        # make a fake ip to trigger the script to send email for the first time
        persist_ip('127.0.0.1')

    saved_ip = read_saved_ip()

    if curr_ip != saved_ip:
        msg = MIMEText(
            f"Public IP address has changed from {saved_ip} to {curr_ip}")
        msg['Subject'] = 'Alert - IP address has changed'
        msg['From'] = settings['from']
        msg['To'] = settings['to']

        send(settings, msg)

        persist_ip(curr_ip)

    else:
        return
Exemplo n.º 7
0
#####MAC ADDRESS
mac = get_mac()
print(mac)

'''######IP
def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(
        s.fileno(),
        0x8915,  # SIOCGIFADDR
        struct.pack('256s', ifname[:15])
    )[20:24])

r = get_ip_address('wlan0') '''
from ipgetter2 import ipgetter1 as ipgetter
IP = ipgetter.myip()
print(IP)
  
# api-endpoint 
URL = "https://2atle79tca.execute-api.us-east-1.amazonaws.com/dev/iot_address_report" #produccion
#URL = "https://2atle79tca.execute-api.us-east-1.amazonaws.com/dev/verificar-visita-qr-lectora" #pruebas

# defining a params dict for the parameters to be sent to the API 
PARAMS = {'cpu_serial':str(cpuserial), 'mac':str(mac), 'IP':str(IP), 'bt_mac':bt_mac}
  
# sending get request and saving the response as response object 
r = requests.get(url = URL, params = PARAMS) 


# extracting data in json format 7
message = r.json()
#! /usr/bin/python3
from ipgetter2 import ipgetter1 as ipgetter
from influxdb import InfluxDBClient
import os, sys
import time, datetime
import MySQLdb
import requests
import getmac
import json
import speedtest

# [School Setup]
school_id = str(sys.argv[1])
school_core_switch_ip = str(sys.argv[2])
school_mac = getmac.get_mac_address()
school_ip = ipgetter.myip()

# [Cloud Setup]
cloudServerProtocol = "http"
# cloudServerIp = "10.0.0.203"
cloudServerIp = str(sys.argv[3])
cloudServerPort = 5000
cloudState = 0 # 0 is connected / 1 is connect fail
edgeNodeRegistUrl = "/edgeNodeRegist"
edgeServiceCheckUrl = "/edgeNodeHealthCheck"
edgeDatabaseFlashUrl = "/edgeNodeSqlUpload"
edgeSpeedtestUploadUrl = "/edgeNodeSpeedtestUpload"

registData = {"school": school_id, "mac": school_mac, "ip": school_ip, "status": ""}
healthData = {"school": school_id, "mac": school_mac, "ip": school_ip, "status":""}
searchSqlData = {"school": school_id, "mac": school_mac, "ip": school_ip, "devices": [], "device_perf": [], "alert_log": [], "ports": []}
Exemplo n.º 9
0
def get_ip():
    return ipgetter.myip()
Exemplo n.º 10
0
# app.py
from flask import Flask  # imports flask
import ipgetter2  # imports ipgetter2
from ipgetter2 import ipgetter1 as ipgetter  # uses the functions of the original ipgetter
myip = ipgetter.myip()  #sets the variable of 'myip' to the external ip address

app = Flask(__name__)  # generated the flask app


@app.route("/")  # at the end point /
def hello():  # call method hello
    return "" + myip  # which returns the external ip address


if __name__ == "__main__":  # on running python app.py
    app.run(
        host='0.0.0.0', port=8080
    )  # run the flask app (add debug=True to run() to enter debug mode)
import getmac
import json

# [Cloud Setup]
cloudServerProtocol = "http"
cloudServerIp = "10.0.0.194"
cloudServerPort = 5000
cloudState = 0  # 0 is connected / 1 is connect fail
edgeNodeRegistUrl = "/edgeNodeRegist"
edgeServiceCheckUrl = "/edgeNodeHealthCheck"
edgeDatabaseFlashUrl = "/edgeNodeSqlUpload"

registData = {
    "school": sys.argv[1],
    "mac": getmac.get_mac_address(),
    "ip": ipgetter.myip(),
    "status": ""
}
healthData = {"school": sys.argv[1], "status": ""}
searchSqlData = {
    "school": sys.argv[1],
    "devices": [],
    "device_perf": [],
    "alert_log": []
}

#print("argv = "+sys.argv[1])
#print(registData)
#print(healthData)

# [Mysql Setup]
Exemplo n.º 12
0
def test_myip():
    ipgetter.myip()
Exemplo n.º 13
0
from ipgetter2 import ipgetter1 as ipgetter
import requests, logging, sys, socket, smtplib, time, json
from requests.auth import HTTPBasicAuth

try:
    import http.client as http_client
except ImportError:
    # Python 2
    import httplib as http_client

publicIP = ipgetter.myip()

ddnsUserName = '******'
ddnsPassword = '******'
ddnsHostName = 'xyz.ddns.net'

## logs
log_f = open('router.log', 'w+')
log = []
log.append(time.strftime('run: %Y-%m-%d %H:%M'))
log.append('Actual public IP: ' + publicIP)

lastPublicIP = socket.gethostbyname(ddnsHostName)

log.append('last public IP: ' + lastPublicIP)

if (publicIP == lastPublicIP):
    log.append('we don\'t do anything')
    log_f.write('\n'.join(log))
    log_f.close()
    sys.exit()