Community discussions

MikroTik App
 
User avatar
Tsunamski
just joined
Topic Author
Posts: 6
Joined: Tue Aug 30, 2016 12:24 pm
Location: Vienna
Contact:

send current IP via mail / mail sending script

Thu Jul 21, 2022 11:26 pm

Hi guys,

I have a bit of a problem I cannot solve:

I configrued and testet /tools email via Winbox.
When I want to send an email with the Send Email Function everything goes well so I believe my smtp config is ok.

Here is the log of a succesful mail:

Jul/21/2022 22:08:57 e-mail,debug recv: 220 gmx.xxx (mrgmx004) Nemesis ESMTP Service ready
Jul/21/2022 22:08:57 e-mail,debug send EHLO [84.112.XXX.XXX]
Jul/21/2022 22:08:58 e-mail,debug recv: 250-gmx.net Hello [84.112.XXX.XXX [84.112.XXX.XXX]
Jul/21/2022 22:08:58 e-mail,debug recv: 250-8BITMIME
Jul/21/2022 22:08:58 e-mail,debug recv: 250-SIZE 69920427
Jul/21/2022 22:08:58 e-mail,debug recv: 250 STARTTLS
Jul/21/2022 22:08:58 e-mail,debug send STARTTLS
Jul/21/2022 22:08:58 e-mail,debug recv: 220 OK
Jul/21/2022 22:08:59 e-mail,debug send EHLO [84.112.XXX.XXX]
Jul/21/2022 22:08:59 e-mail,debug recv: 250-gmx.xxx Hello [84.112.XXX.XXX] [84.112.XXX.XXX]
Jul/21/2022 22:08:59 e-mail,debug recv: 250-8BITMIME
Jul/21/2022 22:08:59 e-mail,debug recv: 250-AUTH LOGIN PLAIN
Jul/21/2022 22:08:59 e-mail,debug recv: 250 SIZE 69920427
Jul/21/2022 22:08:59 e-mail,debug send AUTH PLAIN <CENSORED>
Jul/21/2022 22:09:00 e-mail,debug recv: 235 Authentication succeeded
Jul/21/2022 22:09:00 e-mail,debug send MAIL FROM: <sender@gmx.xxx>
Jul/21/2022 22:09:00 e-mail,debug recv: 250 Requested mail action okay, completed
Jul/21/2022 22:09:00 e-mail,debug send RCPT TO: <recipient@gmx.xxx>
Jul/21/2022 22:09:00 e-mail,debug recv: 250 OK
Jul/21/2022 22:09:00 e-mail,debug send DATA
Jul/21/2022 22:09:00 e-mail,debug recv: 354 Start mail input; end with <CRLF>.<CRLF>
Jul/21/2022 22:09:00 e-mail,debug send .
Jul/21/2022 22:09:00 e-mail,debug recv: 250 Requested mail action okay, completed: id=1MjjCL-1nm8IB0jCF-00lG2o
Jul/21/2022 22:09:00 e-mail,info sent <> to: recipient@gmx.xxx
Jul/21/2022 22:09:00 e-mail,debug send QUIT
Jul/21/2022 22:09:01 e-mail,debug recv: 221 gmx.xxx Service closing transmission channel

So this looks ok,

I found this script and added it under the name checkip
:global ipadd;
:local thisip [/ip address get [find where interface=ether1] address];

:if ($ipadd != $thisip) do={
    /tool e-mail send to="recipient@gmx.xxx" subject="ip change" body="New ip $thisip";
    set ipadd $thisip;
}
when I do
/system script
run checkip

I see the script runs in the log but nothing happens.

Could anyone please give a pointer to why this script fails / does not run correctly?

My IP changes every few months. so I just want to get an email in the morning and when I see it I can take the needed actions.

greetings

Tsunamski
Last edited by rextended on Fri Jul 22, 2022 12:29 am, edited 1 time in total.
 
holvoetn
Forum Guru
Forum Guru
Posts: 5474
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 12:25 am

Most logical answer would be: because there is nothing to do !

Change (to test)
this: :if ($ipadd != $thisip)
to this: :if ($ipadd = $thisip)

So it will do something when the IP adress IS the same.
And then you should see the mail coming.

Don't forget to set it back as it should be.

PS you may want to edit out the credentials in that log-part !
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 12:27 am

You can see my signature???

Do not post values that you do not know what are...

A�p�b�t�b�N�b�1������������=
=
j�n�i�s�o�e@gmx.net�!�3�q�4�7_J�n�i�s

� = censored.....


CHANGE YOUR E-MAIL PASSWORD IMMEDIATELY!!!
 
holvoetn
Forum Guru
Forum Guru
Posts: 5474
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 12:31 am

I was hesitating to "report" but you beat me to it :lol:
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 12:32 am

¯\_(ツ)_/¯

I hope he read fastly, because bots are already indexed the page with the string on plaintext...
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1071
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 12:39 am

Also having several ip addresses on that interface makes the script fail...
 
User avatar
Tsunamski
just joined
Topic Author
Posts: 6
Joined: Tue Aug 30, 2016 12:24 pm
Location: Vienna
Contact:

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 12:45 am

@rextend, I think I dont understand some things here...
I changed my Password, fortunately this was a throwaway account just for sending purposes, I don't use my main mail for test projects.
Simply forgot to change this, dont know why I added this line anyway.
Yes, I can read your signature, but I don't get what I should take away from it.
Or am I just tired and not getting something?
Please explain.

@holvoetn
I made the change but no luck so far.
I am running 7.4rc2 if this makes a difference?

@eworm
no, just the public IP assigned to ether1 the private subnet is configerd on the bridge interface
it's a very basic setup, thats why I dont understand the difficulty to get the address from ether1 and paste it to a mail

greetings Tsunamski
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 12:51 am

@Tsunamski, about the extra text in my signature, is a joke.

P.S.: Nice ‘Avacat’ ;)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 1:20 am

debug code

:global ipadd;
#            ^ not needed

:local thisip [/ip address get [find where interface=ether1] address];
#                                                                    ^ not needed

# [find where interface=ether1] is one array with inside one ID for each IP
# if only one ID is returned, because only one IP is present, "get" can get the IP correctly
# get do not support multiple ID, if are present multimple IPs on that interface, you give error (invalid internal item number)

# how solve
# skip specific addresses like
# [find where interface=ether1 and address!="1.2.3.4/5" and address!="6.7.8.9/10"]
# or
# always retrieve only first ID, but can be the wrong wanted IP...
# :local thisip [/ip address get ([find where interface=ether1]->0) address]
#
# also checking if is returned at least one ID, and exactly one, is better, because prevent errors if 0 IPs are assgned on that interface
# :if ([:len [find where interface=ether1]] = 1) do={ <ok> } else={ <something wrong> }

:if ($ipadd != $thisip) do={
    /tool e-mail send to="recipient@gmx.xxx" subject="ip change" body="New ip $thisip";
#                                                                                     ^ not needed
# the e-mail send command suppose the correct configuration of the e-mail section

#   v Missing : before "set"
    set ipadd $thisip;
#                    ^ not needed
}
 
User avatar
Tsunamski
just joined
Topic Author
Posts: 6
Joined: Tue Aug 30, 2016 12:24 pm
Location: Vienna
Contact:

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 1:38 am

Ok, I am reading this and get more and more question marks above my head.
Is there a documentation on scripting on Mikrotik? I think I need to get some explanations on these functions.
Because if I understood correctly the final code would look like this?
:local thisip [/ip address get ([find where interface=ether1]->0) address]
:if ([:len [find where interface=ether1]] = 1) do={ <ok> } else={ <something wrong> }
:if ($ipadd != $thisip) do={
    /tool e-mail send to="recipient@gmx.xxx" subject="ip change" body="New ip $thisip";
#                                                                                                           ^ not needed
# the e-mail send command suppose the correct configuration of the e-mail section

    v Missing : before "set"
    set ipadd $thisip;
#                    ^ not needed
}
And what I completely not understand is why the variable is not needed?
How else do I get the IP into the mail?
also I always get an auth failed while sending the mail via the send script and not with the winbox gui tool, I think something like TLS?yes is missing...

greetings Jenkins
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 1:58 am

ok.......

i do not think you misunderstand everything......

f code

:global ipadd;
#            ^ not needed
= not needed what is pointed from the ^ symbol = ";" is not needed

f code

# :if ([:len [find where interface=ether1]] = 1) do={ <ok> } else={ <something wrong> }
this is an example, not a code......
<ok> and <something wrong> must be script codes, not literally "<ok>" and "<something wrong>"

f code

#   v Missing : before "set"
    set ipadd $thisip;
what mean???? is not a code, is a warning, miss ":" before "set"....
 
holvoetn
Forum Guru
Forum Guru
Posts: 5474
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 8:15 am

FWIW I tested the original code on my Hex (with the change of != to =) and it worked.
 
User avatar
Tsunamski
just joined
Topic Author
Posts: 6
Joined: Tue Aug 30, 2016 12:24 pm
Location: Vienna
Contact:

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 10:31 am

Hello all,

so I got it to work somehow in the end.
Thank you all for the help.
In the future I will go with more popular mail providers.

@rextended still trying to solve the signature, python only spits out garbage...

So do I mark this as solved or does it not need to be marked?

greetings

Tsunamski
 
holvoetn
Forum Guru
Forum Guru
Posts: 5474
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 12:15 pm

Glad the issue is solved !

It's not needed to mark as solved but it would help for others if you specify what exactly you had to change to make it work.
Surely sooner or later someone will run into the same problem, then it's nice if the solution is also given.
 
User avatar
Tsunamski
just joined
Topic Author
Posts: 6
Joined: Tue Aug 30, 2016 12:24 pm
Location: Vienna
Contact:

Re: send current IP via mail / mail sending script  [SOLVED]

Fri Jul 22, 2022 12:41 pm

So the solution in the end was:

rextendeds code:
:global ipadd;
#            ^ not needed

:local thisip [/ip address get [find where interface=ether1] address];
#                                                                    ^ not needed

# [find where interface=ether1] is one array with inside one ID for each IP
# if only one ID is returned, because only one IP is present, "get" can get the IP correctly
# get do not support multiple ID, if are present multimple IPs on that interface, you give error (invalid internal item number)

# how solve
# skip specific addresses like
# [find where interface=ether1 and address!="1.2.3.4/5" and address!="6.7.8.9/10"]
# or
# always retrieve only first ID, but can be the wrong wanted IP...
# :local thisip [/ip address get ([find where interface=ether1]->0) address]
#
# also checking if is returned at least one ID, and exactly one, is better, because prevent errors if 0 IPs are assgned on that interface
# :if ([:len [find where interface=ether1]] = 1) do={ <ok> } else={ <something wrong> }

:if ($ipadd != $thisip) do={
    /tool e-mail send to="recipient@gmx.xxx" subject="ip change" body="New ip $thisip";
#                                                                                     ^ not needed
# the e-mail send command suppose the correct configuration of the e-mail section

#   v Missing : before "set"
    set ipadd $thisip;
#                    ^ not needed
}
And the second problem were the correct settings for the mail Provider GMX:

address: IP Address here
port: 587
tls: starttls
vrf: main
from: youremail@gmx.xxx
user: youremail@gmx.xxx
password: yourpassword

I had troubles figuring out if the correct login was mail@provider.com@provider.com (some require this form of login) but in the end these settings work for GMX

greetings and many thanks
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: send current IP via mail / mail sending script

Fri Jul 22, 2022 12:57 pm

:roll:
but...... what...... mah......

Who is online

Users browsing this forum: GoogleOther [Bot], Semrush [Bot], UkRainUa and 39 guests