Coder Social home page Coder Social logo

begleysm / ipwatch Goto Github PK

View Code? Open in Web Editor NEW
51.0 51.0 14.0 88 KB

This program gets your external, & internal, IP addresses, checks them against your "saved" IP addresses and, if a difference is found, emails you the new IP(s). This is useful for servers at residential locations whose IP address may change periodically due to actions by the ISP.

Python 100.00%
headless ip remote remote-admin-tool remote-sensing server

ipwatch's People

Contributors

begleysm avatar carolmanderson avatar itsalljustdata avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ipwatch's Issues

Add server used to email to identified faulty server

Sometimes servers begin to report bad IP addresses for one reason or another, but it can become intermittent and difficult to debug.

A simple solution is to inlcude the address of the server that was queried in the email message.

SyntaxWarning: invalid escape sequence '\d'

SyntaxWarning: invalid escape sequence '\d'
Fix: Need to change twice

From
pattern = re.compile("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$")
To
pattern = re.compile(r"^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$")

In lines 165 and 208 of the ipwatch.py file

Thanks for your software
Manuel P

Failure on line 275

It was working as a for loop for 24 hours (because I couldnt get cron to work reliably). I stopped it and wanted to change the email info being used and it wouldnt start again. From /opt/ipwatch or the desktop.
I tried redownloading from source but it gave the same failure. Not sure what to do. Any suggestions?

HELP

Suggestion: Report local IP as well

Make it report local ip's as well, or an config option as to what interfaces to do an additional check
for ip changes.

Example:
Someone else is moving a server to a new network, gets new ip, it gets internet connectivity, send an email about the external and internal ip's. (its behind a firewall, cant connect externally)
Then when I'm at site connecting locally thru same network, I already know the ip. no need to do a netscan.

A hostname can kinda "do" the same thing, but for me its better to know the ip than the hostname.

how to send email to multi users

I want to send mail to multi receivers, How should I do ?

For example, listing all of their email addresses in the receiver_email and delimited by ";" ?

If it's possible, it's better to add an example in readme or wiki.

send email to multi receivers in one shot

Ask for feature to send IP to multi receivers in one email.

My scenario is one of the receiver (for example, [email protected] ), will reponse to the email, notice the result to sender (for example, [email protected]) and other receiver (for example, [email protected] and [email protected]) , which is action result related to IP address ipwatch found ).

If ipwatch can send one email to multi receivers (A/B/[email protected]), then all the receiver can be noticed. Otherwise, B/[email protected] cannot know the result.

In addition, sending email per receiver may easily exceed the daily limitation in some cases.

Discord notifications option

Hi. Thank you for your repo, I found it on stack overflow and loving it.
If you could add notifications via discord webhook URL, it would be awesome and more safer for some users. Thanks!

Specify location for serverCache.json, create option for serverCache update frequency, allow for local server list

Currently serverCache.json is saved to wherever you run the program from. This could be the location of ipwatch.py, it could be the home directory, or somewhere else. This should be normalized and probably made an option in the config.

Currently the update frequency of serverCache.json is hard coded to 90 days. This should probably be made as a config option and should likely default to a more frequent update rate.

There should be an option to use a local server list instead of forcing the SW to use the list from github (and/or overwrite a custom user list when it is updated).

Bad servers

servers.json need to be updated. due to at least one is bad but other than that, great tool.

do "ehlo" after "login"

Is it ok to set value of machine in config.txt when sending mail ?

smtpObj.ehlo(name=machine)

I'd like to identify client in email header, but when I added the above line, I found it did not work.

When I put it after login, it works as expected: the email header contain the string of machine ID.

I am using Python 3.6.8 in centos 7

smtpObj.ehlo()

Save path issue

Hi,
Getting this error when running the test script;

Current IP differs from old IP.
Successfully sent email
Traceback (most recent call last):
  File "/opt/ipwatch/ipwatch.py", line 288, in <module>
    updateoldip(config.save_ip_path,  currip)
  File "/opt/ipwatch/ipwatch.py", line 207, in updateoldip
    savefile = open(filepath, "w")
IsADirectoryError: [Errno 21] Is a directory: '/home/pi/'

Email still sends, so not sure what this means?

Empty Email

received emails with changed ip are empty, there is no new ip.

Do not updating oldip.txt before successfully sending email

hello,

The new ip should not be written into the txt file before program ensure email is successfully sending out.

Sometimes the program did not send email successfully for whatever reason.

# python3 /opt/ipwatch/ipwatch.py /opt/ipwatch/config.txt
GetIP: Try 1: Good IP: xxx.xxx.xxx.xxx
Current IP differs from old IP.
ERROR: unable to send email
#
#
# python3 /opt/ipwatch/ipwatch.py /opt/ipwatch/config.txt
GetIP: Try 1: Good IP: xxx.xxx.xxx.xxx
Current IP = Old IP.  No need to send email.

Then the program will not send the email again on next iteration since it did not know , the last sending did not succeed, it assume that the the ip in oldip.txt is already sent out, So this time "No need to send email" again.

JSON object must be str, not 'bytes

Hi, not sure if this is caused on my end.

two@debiantwo:~$ sudo python3 /opt/ipwatch/ipwatch.py /opt/ipwatch/config.txt [sudo] password for two: Traceback (most recent call last): File "/opt/ipwatch/ipwatch.py", line 278, in <module> currip = getip(int(config.try_count), config.ip_blacklist) File "/opt/ipwatch/ipwatch.py", line 162, in getip currip = ipgetter.myip() File "/opt/ipwatch/ipgetter.py", line 54, in myip return IPgetter().get_externalip() File "/opt/ipwatch/ipgetter.py", line 99, in __init__ theList["servers"] = json.loads(data) File "/usr/lib/python3.5/json/__init__.py", line 312, in loads s.__class__.__name__)) TypeError: the JSON object must be str, not 'bytes'
any idea?

show exception to end-user when sending the email

I recently met an issue during sending email.

I get the error message "unable to send email ...", but it's useful to show the detail exception information to end-user to do the trouble-shooting. Since end-user is repsonsible to fill the config.txt, show the error message on the console is helpful to figure out what's going wrong. especially auth error.

When I remove the try except, I get the internal error msg so I am able to do more investigation.

Current IP differs from old IP.
Traceback (most recent call last):
  File "/opt/ipwatch/ipwatch.py", line 321, in <module>
    sm_ret = sendmail(oldip,  currip,  server, config.sender, config.sender_email, config.receiver, config.receiver_email, config.sender_username, config.sender_password, config.subject_line,  config.machine,  config.smtp_addr)
  File "/opt/ipwatch/ipwatch.py", line 254, in sendmail
    smtpObj.sendmail(sender_email, receiver_emails[i], messages[i])
  File "/usr/lib64/python3.6/smtplib.py", line 888, in sendmail
    raise SMTPDataError(code, resp)
smtplib.SMTPDataError: (550, b'2f1360f5227ac95-29a5c Mail rejected')

how to skip updating servers.json right after cloning

My github access is not stable.
Sometimes, the download speed is quite slow. But more ofter, the download cannot be done due to network issue. If I tried many times and luck enough, the download will be successful.

So if remote version cannot be fetched, and also there is a server.json available locally, Is it possible to config the program not to fetch the remote version ?

Traceback (most recent call last):
  File "/usr/lib64/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/usr/lib64/python3.6/http/client.py", line 1254, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib64/python3.6/http/client.py", line 1300, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib64/python3.6/http/client.py", line 1249, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib64/python3.6/http/client.py", line 1036, in _send_output
    self.send(msg)
  File "/usr/lib64/python3.6/http/client.py", line 974, in send
    self.connect()
  File "/usr/lib64/python3.6/http/client.py", line 1407, in connect
    super().connect()
  File "/usr/lib64/python3.6/http/client.py", line 946, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/lib64/python3.6/socket.py", line 724, in create_connection
    raise err
  File "/usr/lib64/python3.6/socket.py", line 713, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "ipwatch.py", line 281, in <module>
    currip = getip(int(config.try_count), config.ip_blacklist)
  File "ipwatch.py", line 162, in getip
    currip = ipgetter.myip()
  File "/opt/ipwatch/ipgetter.py", line 54, in myip
    return IPgetter().get_externalip()
  File "/opt/ipwatch/ipgetter.py", line 96, in __init__
    operUrl = urllib.urlopen("https://raw.githubusercontent.com/begleysm/ipwatch/master/servers.json")
  File "/usr/lib64/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib64/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/usr/lib64/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/usr/lib64/python3.6/urllib/request.py", line 504, in _call_chain

{
    result = func(*args)
  File "/usr/lib64/python3.6/urllib/request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/usr/lib64/python3.6/urllib/request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 111] Connection refused>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.