Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: GetIP Macro Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: May 20 2004 at 21:08 | IP Logged Quote TonyNo

I'll be the first! Here is a macro that gets your current IP address, and, can e-mail it, or, do anything else when it changes. You need a global variable called IP.

insert into macroheader values ('GET IP 2','GET IP',4,4,252,96,0,0,0,12632256,0,0,1,'',10);
insert into macrodetail values ('GET IP 2',1,15,'[LOCAL1]',NULL,'ph_htmlunescape( ph_geturl( "http://www.ods.org/cgi-bin/myip ,0);
insert into macrodetail values ('GET IP 2',2,16,'',NULL,'if( len( "[LOCAL1]" <> 183, 999 ,1)',0);
insert into macrodetail values ('GET IP 2',3,15,'[LOCAL2]',NULL,'pos( "[LOCAL1]", "/plain") + 8',0);
insert into macrodetail values ('GET IP 2',4,15,'[LOCAL1]',NULL,'mid( "[LOCAL1]", [LOCAL2], 18)',0);
insert into macrodetail values ('GET IP 2',5,15,'[LOCAL1]',NULL,'replace( "[LOCAL1]", 1, 2, "")',0);
insert into macrodetail values ('GET IP 2',6,15,'[LOCAL1]',NULL,'replace( "[LOCAL1]", len( "[LOCAL1]")-1, 2, "")',0);
insert into macrodetail values ('GET IP 2',7,37,'',NULL,'Jump out if same',0);
insert into macrodetail values ('GET IP 2',8,16,'',NULL,'if( "[LOCAL1]" = "{IP}", 999, 1)',0);
insert into macrodetail values ('GET IP 2',9,10,'IP',NULL,'"[LOCAL1]"',0);
insert into macrodetail values ('GET IP 2',12,1,'SETUP EMAIL',0,'',0);
insert into macrodetail values ('GET IP 2',15,20,'',NULL,'"New IP is: " + "{IP}"',0);

Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: May 21 2004 at 23:57 | IP Logged Quote dhoward

Tony,

Excellent!!  This will be a huge boon to users that don't have a static IP.

The only problem is with the second line.  It was causing the import not to succeed properly because of some missing parenthesis, double quote, and single quote.  It's probably the messageboard that caused the failure since it appears to have interpreted it as a link.  The only other prob was I didn't have a macro called 'SETUP EMAIL' either but that would be easy to correct.

I also went ahead and played around with it some and came up with just a slightly different version.  Try it and let me know what you think.

insert into macroheader values ('GET IP 2','GET IP',4,4,252,96,0,0,0,12632256,0,0,1,'',10);
insert into macrodetail values ('GET IP 2',1,15,'[LOCAL1]',NULL,'ph_geturl("www.ods.org/cgi-bin/myip")',0);
insert into macrodetail values ('GET IP 2',2,16,'',NULL,'if(left("[LOCAL1]",12) <> "HTTP/1.1 200",999,1)',0);
insert into macrodetail values ('GET IP 2',3,15,'[LOCAL2]',NULL,'pos("[LOCAL1]", "~r~n~r~n") + 4',0);
insert into macrodetail values ('GET IP 2',4,15,'[LOCAL3]',NULL,'pos("[LOCAL1]","~r~n",[LOCAL2])',0);
insert into macrodetail values ('GET IP 2',5,15,'[LOCAL1]',NULL,'mid("[LOCAL1]",[LOCAL2],[LOCAL3] - [LOCAL2])',0);
insert into macrodetail values ('GET IP 2',6,37,'',NULL,'Jump out if same',0);
insert into macrodetail values ('GET IP 2',7,16,'',NULL,'if("[LOCAL1]" = "{IP}",999,1)',0);
insert into macrodetail values ('GET IP 2',8,10,'IP',NULL,'"[LOCAL1]"',0);

Thanks for making this available for others !!

Dave.

PS.  It was the messageboard that corrupted the link.  I had the same problem.  I went ahead and changed the macro so as not to have the http : // (the ph_geturl function will add it for you if it's not there) and all seems well.

Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: May 22 2004 at 10:41 | IP Logged Quote TonyNo

What is the "~r~n" stuff? Escape sequences?
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: May 22 2004 at 12:21 | IP Logged Quote dhoward

Tony,

Exactly...the ~r is a carriage return and the ~n is a line feed.  PowerHome uses these escape characters for embedding within strings.  Even though it looks as if its 4 characters, a ~r~n actually only counts as 2 characters.  You'll probably remember also the ~t for a tab character.

The ph_geturl function returns the actual HTTP string received from the socket.  So what you'll have is the header information (per the HTTP specification), with each line separated by a carriage return, line feed followed by a double carriage return, line feed pair to signal the start of the HTML and the end of the header.  This is what Im searching on in my macro.

Take care,

Dave.

 

Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
mustangcoupe
Super User
Super User
Avatar

Joined: August 08 2003
Location: United States
Online Status: Offline
Posts: 308
Posted: August 27 2004 at 17:24 | IP Logged Quote mustangcoupe

OK guys.. I am trying to use this macro but I get a windows error when I run it that says....

pwrhome.exe has generated errors and will be closed by windows. You will need to restart the program. An error log has been created.

                        OK


First I dont know where the error log is created.... so I cant look at it.

__________________
Todd Hannemann

HA newbie

   PowerHome - UPB - ELK    
Back to Top View mustangcoupe's Profile Search for other posts by mustangcoupe Visit mustangcoupe's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: September 02 2004 at 17:26 | IP Logged Quote dhoward

Todd,

What version of PowerHome are you running? The error message you're getting is being generated by your OS and not PowerHome. If you're running the latest version, the next thing I would try checking all of the "skip line" boxes and unchecking only 1 at a time (starting with line 10 of course) and try to determine at what line the error occurs. Let me know and I should be able to troubleshoot it a little better.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
mustangcoupe
Super User
Super User
Avatar

Joined: August 08 2003
Location: United States
Online Status: Offline
Posts: 308
Posted: September 04 2004 at 06:19 | IP Logged Quote mustangcoupe

OK, Dave, I am running Wiondows 2k and PowerHom e 1.03.2.
It happens with this line.....

('GET IP 2',7,16,'',NULL,'if("[LOCAL1]" = "{IP}",999,1)',0);

__________________
Todd Hannemann

HA newbie

   PowerHome - UPB - ELK    
Back to Top View mustangcoupe's Profile Search for other posts by mustangcoupe Visit mustangcoupe's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: September 04 2004 at 13:19 | IP Logged Quote dhoward

Todd,

I think Ive found the problem. If you look at the macro line that this SQL corresponds to, you'll see a jump command with a formula that compares the [LOCAL1] system variable to a global variable {IP}. My guess is that you probably don't have a global variable with an ID of "IP" defined. This is my fault since I only exported the macro and did not export any global variables that it may have referenced.

Let me know,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
mustangcoupe
Super User
Super User
Avatar

Joined: August 08 2003
Location: United States
Online Status: Offline
Posts: 308
Posted: September 04 2004 at 14:13 | IP Logged Quote mustangcoupe

Yes Dave I did make a global variable of IP BUT all I did was create one and named it IP but there is no value to it.
I dont know if I did it correctly but I dont see how I could screw it up.

OK I gave it a value and now it seems to work... the variable was initally blank and I guess it didnt like that.


Todd

__________________
Todd Hannemann

HA newbie

   PowerHome - UPB - ELK    
Back to Top View mustangcoupe's Profile Search for other posts by mustangcoupe Visit mustangcoupe's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: September 04 2004 at 16:16 | IP Logged Quote dhoward

Todd,

Great! Glad to hear its working now. Also, the next version has better error checking so this type of error while still not working should not crash PowerHome hard.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum