Email wan IP address
Moderators: JRL, Dorian (MJT support)
Email wan IP address
This may be a little brute force but it works. I wanted to connect to my home pc using remote desktop. I'm directly connected through a dsl modem with a non-microsoft firewall. I enabled the proper port and it works great. Problem is my ip address is not static. Tried several of the services that will provide a domain name and provide software to periodically update their dns server with the wan side ip address but wasn't real happy with it. So figured I could roll my own using ms.
I used the smtp mailer example as a starting point and then modified so it would email my ip address to an internet account periodically using a cmd /c route print to file and then extracting the proper line of the file that contained the ip address.
One of my co-workers asked if I could modify the program so he could use it as well. Problem was he's behind a dsl router and my simple route print to file wouldn't work for him. Also, I had embedded most of the static info in the exe so would have to modify all in order to give to someone else. So decided to use an ini that would allow anyone to change the parameters and make the program then work for them.
I use a route print command to pull the local ip statics of the pc and then a tracert with a few hops to microsoft.com to pull out the wan ip...usually the second hop. Guess I could have picked out the specific lines in each file to simplify it even more but it works well enough.
Was just looking at the code and guess it would have been better not to put static paths..then it could be installed and run from any subdirectory instead of the way I have it set now.
Just thought I'd share.
***script follows***
Let>APP_TITLE=My IP Mailer
Let>RP_Windowmode=0
Let>RP_WAIT=1
Run Program>c:\windows\system32\cmd.exe /c tracert -d -h 4 http://www.microsoft.com > c:\ipmailer\wanip.txt
Run Program>c:\windows\system32\cmd.exe /c route print > c:\ipmailer\localip.txt
Let>BODY=
ReadFile>c:\ipmailer\localip.txt,LOCALIP
ReadFile>c:\ipmailer\wanip.txt,WANIP
LET>BODY=%LOCALIP%%CRLF%%WANIP%
Let>POSTOFFICE=
Let>POACCOUNT=
Let>POPASSWORD=
Let>MYNAME=
Let>TOWHO=
Wait>2
ReadIniFile>c:\ipmailer\ipmailer.ini,settings,POSTOFF,POSTOFFICE
ReadIniFile>c:\ipmailer\ipmailer.ini,settings,POACCT,POACCOUNT
ReadIniFile>c:\ipmailer\ipmailer.ini,settings,POPASS,POPASSWORD
ReadIniFile>c:\ipmailer\ipmailer.ini,settings,NAME,MYNAME
ReadIniFile>c:\ipmailer\ipmailer.ini,settings,TO,TOWHO
Let>SUBJECT=Your current IP address
Let>SMTP_AUTH=1
Let>SMTP_USERID=POACCOUNT
Let>SMTP_PASSWORD=POPASSWORD
SMTPSendMail>TOWHO,POSTOFFICE,POACCOUNT,MYNAME,SUBJECT,BODY,
***msg>%TOWHO%,%CRLF%%POSTOFFICE%,%CRLF%%POACCOUNT%,%CRLF%%MYNAME%,%CRLF%%SUBJECT%,%CRLF%%BODY%,
**Message>Result of SendMail: %SMTP_RESULT%
Label>end
****end script***
My ini file is simple enough
[settings]
NAME=John Doe
POSTOFF=SMTP.MYISP.COM
POACCT=[email protected]
POPASS=password
TO=[email protected], [email protected]
I used the smtp mailer example as a starting point and then modified so it would email my ip address to an internet account periodically using a cmd /c route print to file and then extracting the proper line of the file that contained the ip address.
One of my co-workers asked if I could modify the program so he could use it as well. Problem was he's behind a dsl router and my simple route print to file wouldn't work for him. Also, I had embedded most of the static info in the exe so would have to modify all in order to give to someone else. So decided to use an ini that would allow anyone to change the parameters and make the program then work for them.
I use a route print command to pull the local ip statics of the pc and then a tracert with a few hops to microsoft.com to pull out the wan ip...usually the second hop. Guess I could have picked out the specific lines in each file to simplify it even more but it works well enough.
Was just looking at the code and guess it would have been better not to put static paths..then it could be installed and run from any subdirectory instead of the way I have it set now.
Just thought I'd share.
***script follows***
Let>APP_TITLE=My IP Mailer
Let>RP_Windowmode=0
Let>RP_WAIT=1
Run Program>c:\windows\system32\cmd.exe /c tracert -d -h 4 http://www.microsoft.com > c:\ipmailer\wanip.txt
Run Program>c:\windows\system32\cmd.exe /c route print > c:\ipmailer\localip.txt
Let>BODY=
ReadFile>c:\ipmailer\localip.txt,LOCALIP
ReadFile>c:\ipmailer\wanip.txt,WANIP
LET>BODY=%LOCALIP%%CRLF%%WANIP%
Let>POSTOFFICE=
Let>POACCOUNT=
Let>POPASSWORD=
Let>MYNAME=
Let>TOWHO=
Wait>2
ReadIniFile>c:\ipmailer\ipmailer.ini,settings,POSTOFF,POSTOFFICE
ReadIniFile>c:\ipmailer\ipmailer.ini,settings,POACCT,POACCOUNT
ReadIniFile>c:\ipmailer\ipmailer.ini,settings,POPASS,POPASSWORD
ReadIniFile>c:\ipmailer\ipmailer.ini,settings,NAME,MYNAME
ReadIniFile>c:\ipmailer\ipmailer.ini,settings,TO,TOWHO
Let>SUBJECT=Your current IP address
Let>SMTP_AUTH=1
Let>SMTP_USERID=POACCOUNT
Let>SMTP_PASSWORD=POPASSWORD
SMTPSendMail>TOWHO,POSTOFFICE,POACCOUNT,MYNAME,SUBJECT,BODY,
***msg>%TOWHO%,%CRLF%%POSTOFFICE%,%CRLF%%POACCOUNT%,%CRLF%%MYNAME%,%CRLF%%SUBJECT%,%CRLF%%BODY%,
**Message>Result of SendMail: %SMTP_RESULT%
Label>end
****end script***
My ini file is simple enough
[settings]
NAME=John Doe
POSTOFF=SMTP.MYISP.COM
POACCT=[email protected]
POPASS=password
TO=[email protected], [email protected]
- CyberCitizen
- Automation Wizard
- Posts: 724
- Joined: Sun Jun 20, 2004 7:06 am
- Location: Adelaide, South Australia
Check Out This Post.
http://www.mjtnet.com/usergroup/viewtopic.php?t=2333
This Was Written For Something Else, However I Am Sure You Could Modify It To Suit Your Needs.
However Myself I Use dyndns.org & Have My Router Update If The IP Changes. Works Fine Never Had A Problem, I Also Have A Static IP Though, It Was Suppost To Be Dynmatic.
Suggest You Check Your Router, Because If You Can Have Your Router Do It, It Would Be Alot Easier.
http://www.mjtnet.com/usergroup/viewtopic.php?t=2333
This Was Written For Something Else, However I Am Sure You Could Modify It To Suit Your Needs.
However Myself I Use dyndns.org & Have My Router Update If The IP Changes. Works Fine Never Had A Problem, I Also Have A Static IP Though, It Was Suppost To Be Dynmatic.
Suggest You Check Your Router, Because If You Can Have Your Router Do It, It Would Be Alot Easier.
FIREFIGHTER
Knew there was proably an easier way to do this. Have noticed something odd though...every once in a while it drops the first number of the ip address. If the ip is 65.64.....it reports it as 5.64....Me_again wrote:Another way to get the wan IP that works well for me:
Let>HTTP_TIMEOUT=5
HTTPRequest>http://www.whatismyip.com,,GET,,HTMLResponse
Position>Your,HTMLResponse,1,StartPos
Add>StartPos,12
Position> ,HTMLResponse,StartPos,Endpos
MidStr>HTMLResponse,StartPos,EndPos,YourIP
MessageModal>YourIP
Will play with this as I don't fully understand how it's picking the ip address from the web page.
thanks
- CyberCitizen
- Automation Wizard
- Posts: 724
- Joined: Sun Jun 20, 2004 7:06 am
- Location: Adelaide, South Australia
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
I don't know why it's not working consitently for you, but cybercitizen's dyndns is probably a better page to use anyway. Try this:
Let>HTTP_TIMEOUT=5
HTTPRequest>http://checkip.dyndns.org,,GET,,HTMLResponse
MessageModal>HTMLResponse
Position>:,HTMLResponse,1,StartPos
MessageModal>StartPos
Add>StartPos,2
Position>Endpos
Sub>Endpos,1
MidStr>HTMLResponse,StartPos,EndPos,YourIP
MessageModal>YourIP
Let>HTTP_TIMEOUT=5
HTTPRequest>http://checkip.dyndns.org,,GET,,HTMLResponse
MessageModal>HTMLResponse
Position>:,HTMLResponse,1,StartPos
MessageModal>StartPos
Add>StartPos,2
Position>Endpos
Sub>Endpos,1
MidStr>HTMLResponse,StartPos,EndPos,YourIP
MessageModal>YourIP
- CyberCitizen
- Automation Wizard
- Posts: 724
- Joined: Sun Jun 20, 2004 7:06 am
- Location: Adelaide, South Australia
This Is The Code I Use. It Also Strips All Text So You Only Get The IP Address & Thats It.
//Users IP Address
HTTPRequest>http://checkip.dyndns.org/,,GET,,HTMLResponse
MidStr>%HTMLResponse%,77,15,IPAddress
StringReplace>%IPAddress%,/,,IPAddress
StringReplace>%IPAddress%,%IPAddress%, ,,IPAddress
StringReplace>%IPAddress%,b,,IPAddress
StringReplace>%IPAddress%,o,,IPAddress
StringReplace>%IPAddress%,d,,IPAddress
MessageModal>%IPAddress%
//Users IP Address
HTTPRequest>http://checkip.dyndns.org/,,GET,,HTMLResponse
MidStr>%HTMLResponse%,77,15,IPAddress
StringReplace>%IPAddress%,/,,IPAddress
StringReplace>%IPAddress%,%IPAddress%, ,,IPAddress
StringReplace>%IPAddress%,b,,IPAddress
StringReplace>%IPAddress%,o,,IPAddress
StringReplace>%IPAddress%,d,,IPAddress
MessageModal>%IPAddress%
FIREFIGHTER
cual es mi ip?
hola esta es la forma q yo uso para saber la direccion ip
HTTPRequest>http://checkip.dyndns.org/,,GET,,HTMLResponse
Position>:,%HTMLResponse%,1,IP
let>ip=ip+2
Position>,%HTMLResponse%,%ip%,final
let>final=final-1
MidStr>%HTMLResponse%,%IP%,%final%,AIP
Message>AIP
chao

HTTPRequest>http://checkip.dyndns.org/,,GET,,HTMLResponse
Position>:,%HTMLResponse%,1,IP
let>ip=ip+2
Position>,%HTMLResponse%,%ip%,final
let>final=final-1
MidStr>%HTMLResponse%,%IP%,%final%,AIP
Message>AIP

chao
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
If you have access to a webserver with php (almost all hosts offer php) you can be independent of third party IP services by creating and uploading a .php file containing:
HTTPRequest to http://www.yourdomain.com/whatever.php will return just the IP address so there's no issue with changing formats or need to filter text.
The name of the .php file is your choice, I would call it something obscure rather than "whatismyip.php" to avoid inadvertently providing a public service
Code: Select all
<?php echo $REMOTE_ADDR ?>
The name of the .php file is your choice, I would call it something obscure rather than "whatismyip.php" to avoid inadvertently providing a public service
