forked from iordic/IPSender
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
352 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
# IPSender | ||
Simple commandline tool to send public ip through e-mail. Thought to run as service. | ||
Simple commandline tool to send public ip through e-mail. | ||
Thought to run as service. | ||
|
||
## How to use? | ||
* Configure "mail.json" with your login credentials. | ||
* Password requires base64 encoding, use codepass.py for this and encode your password. | ||
 | ||
* Set receiver address where program sends the IP. | ||
* If you aren't using gmail, change smtp config. | ||
* Configure _config.json_ with your login credentials. | ||
See configuration section. | ||
* Execute _ipsender.py_ and it will do the job. :) | ||
|
||
## TO DO | ||
- [x] Send e-mails to multiple addresses. | ||
- [ ] Use encryption for the password field. | ||
- [x] PEP8 Style | ||
## Configuration | ||
To configure credentials and server configuration, type: | ||
``` | ||
python ipsender.py -c | ||
``` | ||
And then fill the questions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"login" : { | ||
"user" : "[email protected]", | ||
"password" : "3uNKNIrecDo=", | ||
"key" : "XgKx/Uc5gq4=" | ||
}, | ||
"sender" : "[email protected]", | ||
"receiver" : "[email protected]", | ||
"protocol" : "smtp", | ||
"server" : "smtp.gmail.com", | ||
"port" : "587" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"messages" : [ | ||
{ | ||
"lang" : "en", | ||
"text" : { | ||
"subject" : "Current IP", | ||
"ip" : "The public IP is: ", | ||
"user" : "The logged user is: ", | ||
"name" : "Computer name: ", | ||
"os" : "Operating System: ", | ||
"version" : "Version: ", | ||
"release" : "Release: ", | ||
"machine" : "Architecture: ", | ||
"processor" : "Processor: " | ||
} | ||
}, | ||
{ | ||
"lang" : "es", | ||
"text" : { | ||
"subject" : "IP actual", | ||
"ip" : "La IP publica es: ", | ||
"user" : "El usuario identificado es: ", | ||
"name" : "Nombre del ordenador: ", | ||
"os" : "Sistema Operativo: ", | ||
"version" : "Version: ", | ||
"release" : "Release: ", | ||
"machine" : "Arquitectura: ", | ||
"processor" : "Procesador: " | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import json | ||
import os | ||
import getpass | ||
import base64 | ||
from tools.Obfuscator import Obfuscator | ||
|
||
|
||
class Configuration: | ||
def __init__(self, f): | ||
self.file = f | ||
if os.path.isfile(self.file): | ||
self.load_data() | ||
else: | ||
raise Exception('File not found: config.json, try using -c parameter.') | ||
|
||
def load_data(self): | ||
""" Load the json data in the config.json file. """ | ||
try: | ||
with open(self.file, 'r') as json_file: | ||
self.data = json.load(json_file) | ||
self.user = self.data['login']['user'] | ||
self.password = self.data['login']['password'] | ||
self.key = self.data['login']['key'] | ||
self.sender = self.data['sender'] | ||
self.receiver =self.data['receiver'] | ||
self.protocol = self.data['protocol'] | ||
self.server = self.data['server'] | ||
self.port = self.data['port'] | ||
except IOError as err: | ||
print "Can't open file" | ||
|
||
def update_file(self): | ||
""" Replaces config.json file with the new data. """ | ||
with open(self.file, 'w') as json_file: | ||
json.dump(self.data, json_file) | ||
|
||
def configure(self): | ||
""" Configuration method for creating the config.json file or replace it. """ | ||
with open('./data/config_template.json', 'r') as template: | ||
json_data = json.load(template) | ||
print '\nLogin configuration:' | ||
print '====================' | ||
json_data['login']['user'] = raw_input('Enter username: ') | ||
password = getpass.getpass('Enter password: ') | ||
o = Obfuscator(password) | ||
json_data['login']['password'] = base64.b64encode(o.cpassword) | ||
json_data['login']['key'] = base64.b64encode(o.key) | ||
del o | ||
print '\nE-mail options:' | ||
print '=================' | ||
json_data['sender'] = raw_input('Enter the sender address: ') | ||
json_data['receiver'] = raw_input('Enter the receiver address: ') | ||
print '\nServer options:' | ||
print '===============' | ||
server = raw_input('Enter the server address (blank for smtp.gmail.com): ') | ||
if server != '': | ||
json_data['server'] = server | ||
protocol = raw_input('Enter the protocol (blank for smtp): ') | ||
if protocol != '': | ||
json_data['protocol'] = protocol | ||
port = raw_input('Enter the port (blank for 587): ') | ||
if port != '': | ||
json_data['port'] = port | ||
self.data = json_data | ||
self.update_file() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import json | ||
|
||
|
||
class Message: | ||
def __init__(self, f, lang='en'): | ||
with open(f) as json_file: | ||
data = json.load(json_file) | ||
language_position = self.check_language(lang, data) | ||
if language_position < 0: | ||
self.language = 'en' | ||
language_position = 0 | ||
else: | ||
self.language = lang | ||
self.subject = data['messages'][language_position]['text']['subject'] | ||
self.ip = data['messages'][language_position]['text']['ip'] | ||
self.user = data['messages'][language_position]['text']['user'] | ||
self.name = data['messages'][language_position]['text']['name'] | ||
self.os = data['messages'][language_position]['text']['os'] | ||
self.version = data['messages'][language_position]['text']['version'] | ||
self.release = data['messages'][language_position]['text']['release'] | ||
self.machine = data['messages'][language_position]['text']['machine'] | ||
self.processor = data['messages'][language_position]['text']['processor'] | ||
|
||
def check_language(self, lang, data): | ||
""" Check if language exists on json file. If exists | ||
return the language position. If not return -1. """ | ||
for i in range(0, len(data['messages'])): | ||
if data['messages'][i]['lang'] == lang: | ||
return i | ||
return -1 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:: Run all script tests from tests folder | ||
python -m unittest discover tests |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import unittest | ||
from tools.Obfuscator import Obfuscator | ||
|
||
|
||
class TestObfuscator(unittest.TestCase): | ||
|
||
def setUp(self): | ||
pass | ||
|
||
def test_mix_keys(self): | ||
""" Check the password encryption and decryption. """ | ||
# Password encryption | ||
first = Obfuscator('1234') | ||
first_key = first.key | ||
first_cpassword = first.cpassword | ||
# Password decryption | ||
second = Obfuscator(first_cpassword, first_key) | ||
# Decrypted password should be same as first password | ||
expected = first.password | ||
actual = second.cpassword | ||
self.assertEqual(expected, actual) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.