local/remote script question 
Author Message
 local/remote script question

I was wondering how I could have a local PHP (4.2.3) script running on Apache
1.3.27 / WinXP Pro send my current local IP address to a remote server running
PHP 4.1.2, RedHat 7.3 & Apache 1.3.26.. In the Linux based script, I'd want it
to basically display my current IP address to friends who know the remote URL to
connect to my FTP/HTTP server(s) and grab mp3s, etc..

I'm a complete newbie, and in my php.net/google.com searches the only thing I've
come across is something called a CRON Job.. From my little experience and
understanding, I've always thought a Cron Job was something that only was valid
on *nix platforms and not Win32.. Am I mistaken?  My remote linux server has a
dedicated IP, although my Win32 machine obviously doesn't.. I assume this would
make it easier to communicate from local to remote?

From my little understanding, I assume the local script would need to place my
IP address in a variable (ie: $ipaddress = ""; within say ipaddy.inc) and the
remote script would be updated as the variable was read from ipaddy.inc when
someone visited the page..?

If anyone could point me to a tutorial, function name(s) or offer some code to
get me started, I'd greatly appreciate it.. Apache & PHP load on my local
(Win32) machine when it boots and it's always running.. I just can't get past
the auto-run-a-local-php-script area for the most part..

TIA..

Take care.. peace..
eriol



Sun, 22 May 2005 07:51:00 GMT  
 local/remote script question
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quote:

> I was wondering how I could have a local PHP (4.2.3) script running on
> Apache 1.3.27 / WinXP Pro send my current local IP address to a remote
> server running PHP 4.1.2, RedHat 7.3 & Apache 1.3.26.. In the Linux based
> script, I'd want it to basically display my current IP address to friends
> who know the remote URL to connect to my FTP/HTTP server(s) and grab mp3s,
> etc..

On the windows machine, you can make a batch file containing something like

C:\php\php.exe -q C:\files\roulette\oltimey.php

and name it something like C:\php\scriptrunner.bat

Then you can either use the AT command (try "help at" from the command line)

or simply use the task scheduler. If you want to run it every minute or
something, you'll wish you were using cron. ;-) I would Search google for a
Windows cron.

Best,

- --
Waitman Gobble         EMK Design     Buena Park, California

Public Key                          http://pgp.emkdesign.com
Find an example                    http://freakinexample.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE97X8tlkBqm2sl6RIRAhndAJwOsbeaO3KWhzWBZDr8qnJSm7uSzgCcCerV
YAyHHUOEqlUu7FmtDvhXRn0=
=a+qc
-----END PGP SIGNATURE-----



Sun, 22 May 2005 12:05:22 GMT  
 local/remote script question

: On the windows machine, you can make a batch file containing something like
:
: C:\php\php.exe -q C:\files\roulette\oltimey.php
:
: and name it something like C:\php\scriptrunner.bat
:
: Then you can either use the AT command (try "help at" from the command line)
:
: or simply use the task scheduler. If you want to run it every minute or
: something, you'll wish you were using cron. ;-) I would Search google for a
: Windows cron.

====

Thanks for the reply.. I didn't realize there was an "AT" command in Windows and
I assumed the Task Scheduler would come into this somehow, but I wasn't sure
about the batch file part.. I understand that now and appreciate the help.. I'm
looking into both options as well as WinCron..

What I'm stuck with now is functions that would perform what I want.. Again,
it's getting IP Address from Win32 local machine to RedHat remote machine and
have it displayed within a php page on the remote machine.. One question I have
about the local IP address is SERVER_ADDR & HTTP_HOST always comes up as my
machine name or a loopback (127.0.0.1 / localhost).. What Apache or PHP variable
is appropriate for finding out the true IP address?

Could you, or anyone else, offer some function names to look into to get my IP
from here to there as a variable?  I don't expect code to be written for me, but
function names would get me started.. If you're feeling generous, please leave
an small example.. TIA..

Take care.. peace..
eriol



Mon, 23 May 2005 03:31:49 GMT  
 local/remote script question
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quote:

> Could you, or anyone else, offer some function names to look into to get
> my IP
> from here to there as a variable?  I don't expect code to be written for
> me, but function names would get me started.. If you're feeling generous,
> please leave an small example.. TIA..

Hey

This works on my xp pro machine. It should work on other systems but you may
have to fiddle with it.

There may be an easier way, probably a better way, however this was the
first thing that popped in my head that would automagically get the correct
address even if the dhcp lease expires and is renewed. I only had about 5
minutes to work on this, but it does work when tested on my machine ;-)

I assume the following:

a) you are using an ipv4 address.
b) you have a single ethernet adapter, without a modem or other network
device.
c) your "ipconfig.exe" is in C:\Windows\System32

You will likely find that you cannot run the script from your browser
because (ideally) the user that carries the web server process can't
execute stuff in your system directory... But this shouldn't matter because
you are going to run it from the command line anyhow.

<?php

$stuff = array();

exec ("c:\\windows\\system32\\ipconfig.exe",$stuff);

$ip=explode(".",strrev($stuff[7]));

$address =
        trim(
        ereg_replace(":","",
                strrev(
                        array_shift($ip).".".
                        array_shift($ip).".".
                        array_shift($ip).".".
                        array_shift($ip))));

echo $address;

?>

Best,

- --
Waitman Gobble         EMK Design     Buena Park, California

Public Key                          http://pgp.emkdesign.com
Find an example                    http://freakinexample.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE97nknlkBqm2sl6RIRAqn2AJ4kX+yQWMam9wJFTJ/5qm9AbTDSPgCdHMJ1
9/PO/+14lUnta0KGRqHMHfE=
=9ZIA
-----END PGP SIGNATURE-----



Mon, 23 May 2005 05:51:46 GMT  
 local/remote script question

Quote:
> > Could you, or anyone else, offer some function names to look into to get
> > my IP
> > from here to there as a variable?

> <?php

> $stuff = array();

> exec ("c:\\windows\\system32\\ipconfig.exe",$stuff);

> $ip=explode(".",strrev($stuff[7]));

> $address =
>         trim(
>         ereg_replace(":","",
>                 strrev(
>                         array_shift($ip).".".
>                         array_shift($ip).".".
>                         array_shift($ip).".".
>                         array_shift($ip))));

> echo $address;

> ?>

On my Win2k box this give the Subnet Mask (255.255.255.0)
It is possible that different versions of windows
write out ipconfig differently.

This may be better:

$stuff = array();
exec('c:/.. systempath ../ipconfig.exe', $stuff);

for ($i=4; $i<count($stuff); $i++) {
    if (strstr($stuff[$i], 'IP Address')) {
        $address = trim(array_pop(explode(':', $stuff[$i])));
        break;
    }

Quote:
}

echo $address;

regards,
reggie.

p.s. this is shorter & relies on
only one func call, but is more obfuscated:

for ($i=4; $i<count($stuff); $i++) {
    if (preg_match('/IP Address.*?:\s([\d.]+)/', $stuff[$i], $out)) {
        $address = $out[1];
        break;
    }

- Show quoted text -

Quote:
}



Mon, 23 May 2005 06:42:23 GMT  
 local/remote script question

Quote:

> What I'm stuck with now is functions that would perform what
> I want.. Again, it's getting IP Address from Win32 local machine
> to RedHat remote machine and have it displayed within a php page
> on the remote machine..

What happens if you use $_SERVER["REMOTE_ADDR"] ON THE REMOTE MACHINE?

Quote:
> One question I have about the local IP address is SERVER_ADDR &
> HTTP_HOST always comes up as my machine name or a loopback
> (127.0.0.1 / localhost).. What Apache or PHP variable is
> appropriate for finding out the true IP address?

There may be none on a local machine...  You have to look at it from
the remote machine's viewpoint...

Quote:
> If you're feeling generous, please leave an small example..

OK, let's say your remote Linux machine is remote.com, your local
Windows machine is... well, whatever.

So on the Windows machine, you have a script that has this line:

readfile ("http://remote.com/getipaddr.php");

On the remote Linux machine, getipaddr.php could look like this:

$ip = $_SERVER["REMOTE_ADDR"];
echo "<p>Your remote IP address is $ip </p>";
$fp = fopen ("myipaddr.htm", "w");
fputs ($fp, "<META name=\"Expires\" content=\"" .
            gmdate("D, d M Y H:i:s") . " GMT> \n");
fputs ($fp, "<p>Last I checked, my IP adress was ".
            "<a href=\"http://". $ip ."/\"</a></p> \n");
fclose ($fp);
echo "<p>File <tt>myipaddr.htm</tt> regenerated successfully </p>";

Then give your friends this URL:

http://remote.com/myipaddr.htm

and it should take care of your problem...

Cheers,
NC



Mon, 23 May 2005 09:40:07 GMT  
 local/remote script question


: On my Win2k box this give the Subnet Mask (255.255.255.0)
: It is possible that different versions of windows
: write out ipconfig differently.
:
: This may be better:
:
: $stuff = array();
: exec('c:/.. systempath ../ipconfig.exe', $stuff);
:
: for ($i=4; $i<count($stuff); $i++) {
:     if (strstr($stuff[$i], 'IP Address')) {
:         $address = trim(array_pop(explode(':', $stuff[$i])));
:         break;
:     }
: }
:
: echo $address;
:
: regards,
: reggie.
:
: p.s. this is shorter & relies on
: only one func call, but is more obfuscated:
:
: for ($i=4; $i<count($stuff); $i++) {
:     if (preg_match('/IP Address.*?:\s([\d.]+)/', $stuff[$i], $out)) {
:         $address = $out[1];
:         break;
:     }
: }

====

Thanks again for the replies Waitman & Reggie..

I tried both of your examples in a file called ipaddr.php.. I opened up the CMD
prompt, went to the directory and simply typed in ipaddr.php, something happened
and the cmd window went to the background of other windows i had opened.. I
thought there was a "run" command in Windows DOS prompt, but I guess I am
mistaken or don't know how to use it.. If it's any help, my path to ipconfig.exe
is C:/WINNT/system32/ipconfig.exe.. That brings me to another question.. What's
the difference between two backslashes separating directories to one forward
slash?  Is one better than the other? Also, Apache & PHP are installed on a
seperate drive than ipconfig.. I don't assume this would make a difference as
they're both run under the same priviledges from the Administrator account and
the php.ini is in my C: drive as well.. Apache & PHP are under D:/Apache/ and
D:/Apache/PHP/ and my Docroot is also on my D: drive..

When adding either of your scripts to my task scheduler, how exactly do they
work?  I don't see anything within either of your scripts that would send this
information to my Linux remote server.. Only that they execute the ipconfig
locally and print it out, assuming I'd went to it with a browser (which only
returns 0.0.0.0 as an output)..

Please enlighten me a bit more.. Sorry for the 20 questions.. I am trying to
grasp this, just want to make sure I'm on the same page as you guys and able to
understand what exactly everything is doing.. I understand what the functions
you've both used do, and that they echo $address.. But where is the $address
variable echo'd and how would my Linux server get this information from my local
WinXP Pro machine?

Thanks again for the replies and TIA for any further.. Sorry for the newbie
questions.. I appreciate the help..

Take care.. peace..
eriol



Mon, 23 May 2005 10:27:21 GMT  
 local/remote script question


:
: What happens if you use $_SERVER["REMOTE_ADDR"] ON THE REMOTE MACHINE?
:
: There may be none on a local machine...  You have to look at it from
: the remote machine's viewpoint...
:
: OK, let's say your remote Linux machine is remote.com, your local
: Windows machine is... well, whatever.
:
: So on the Windows machine, you have a script that has this line:
:
: readfile ("http://remote.com/getipaddr.php");
:
: On the remote Linux machine, getipaddr.php could look like this:
:
: $ip = $_SERVER["REMOTE_ADDR"];
: echo "<p>Your remote IP address is $ip </p>";
: $fp = fopen ("myipaddr.htm", "w");
: fputs ($fp, "<META name=\"Expires\" content=\"" .
:             gmdate("D, d M Y H:i:s") . " GMT> \n");
: fputs ($fp, "<p>Last I checked, my IP adress was ".
:             "<a href=\"http://". $ip ."/\"</a></p> \n");
: fclose ($fp);
: echo "<p>File <tt>myipaddr.htm</tt> regenerated successfully </p>";
:
: Then give your friends this URL:
:
: http://remote.com/myipaddr.htm

====

Thanks for your reply Nikolai..

I wasn't clear enough in my initial post, but I was/am using
$_SERVER["REMOTE_ADDR"] and not just $REMOTE_ADDR.. Either means returns only a
loopback or my PC name..

I understand your script, but I'm running into the same problem of
non-understanding that I did with reggie's and waitman's replies earlier in the
thread.. How does the script on my remote linux server (remote.com for example)
get the information of my local IP from my WinXP Pro (local.com for example)?

Neither machine are on the same network.. My local machine (WinXP Pro) is
connected fairly often, but if I need to reboot, I want my Linux server (a paid
host on 24/7) to be able to update the new IP change..

I hope I'm not missing the obvious here.. If I am, my apologies.. I again just
want to make sure I'm following and understand your replies.. I do appreciate
everyone's help thus far..

Take care.. peace..
eriol



Mon, 23 May 2005 10:33:38 GMT  
 local/remote script question
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quote:

> On my Win2k box this give the Subnet Mask (255.255.255.0)
> It is possible that different versions of windows
> write out ipconfig differently.

> p.s. this is shorter & relies on
> only one func call, but is more obfuscated:

> for ($i=4; $i<count($stuff); $i++) {
>     if (preg_match('/IP Address.*?:\s([\d.]+)/', $stuff[$i], $out)) {
>         $address = $out[1];
>         break;
>     }
> }

Thanks, I agree this is MUCH better. You are correct that you can't count on
the results being on the same line across various machines, I was figuring
just changing the #.

Windows 2000 Server:

$ ipconfig

Windows 2000 IP Configuration

Ethernet adapter Local Area Connection:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.0.98
        Subnet Mask . . . . . . . . . . . : 255.255.255.224
        Default Gateway . . . . . . . . . : 192.168.0.97

Ethernet adapter Local Area Connection 2:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.0.109
        Subnet Mask . . . . . . . . . . . : 255.255.255.224
        IP Address. . . . . . . . . . . . : 192.168.0.108
        Subnet Mask . . . . . . . . . . . : 255.255.255.224
        IP Address. . . . . . . . . . . . : 192.168.0.107
        Subnet Mask . . . . . . . . . . . : 255.255.255.224
        IP Address. . . . . . . . . . . . : 192.168.0.106
        Subnet Mask . . . . . . . . . . . : 255.255.255.224
        IP Address. . . . . . . . . . . . : 192.168.0.105
        Subnet Mask . . . . . . . . . . . : 255.255.255.224
        IP Address. . . . . . . . . . . . : 192.168.0.104
        Subnet Mask . . . . . . . . . . . : 255.255.255.224
        IP Address. . . . . . . . . . . . : 192.168.0.103
        Subnet Mask . . . . . . . . . . . : 255.255.255.224
        Default Gateway . . . . . . . . . :

and Windows XP Pro:

$ ipconfig

Windows IP Configuration

Ethernet adapter Local Area Connection:

        Connection-specific DNS Suffix  . : emkhost.com
        IP Address. . . . . . . . . . . . : 192.168.0.165
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.0.2

For some reason it has an extra "blank" line after "Windows IP
Configuration".... hmmm....

Best,

- --
Waitman Gobble         EMK Design     Buena Park, California

Public Key                          http://pgp.emkdesign.com
Find an example                    http://freakinexample.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE97sYvlkBqm2sl6RIRAvrDAJ472w7DRtewgL3A3XRUCuBmQAMCCgCfcC3c
I567q6ke1B4noObxYwz1q94=
=GsgT
-----END PGP SIGNATURE-----



Mon, 23 May 2005 11:20:23 GMT  
 local/remote script question
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quote:

> I tried both of your examples in a file called ipaddr.php.. I opened up
> the CMD prompt, went to the directory and simply typed in ipaddr.php,
> something happened and the cmd window went to the background of other
> windows i had opened..

Well, you need to call the php executable and send the script filename as
the first argument, like

PROMPT> c:\php\php.exe c:\scriptlocation\ipaddr.php

if you use the -q option it won't print any header information (probably
what you want to do).

PROMPT> c:\php\php.exe -q c:\scriptlocation\ipaddr.php

Quote:
> What's the difference between two
> backslashes separating directories to one forward
> slash?  Is one better than the other?

Technically software like Apache and PHP make one in the same, however I
read someone's post in here claiming that Apache don't like the \\, and
enjoys "/" much better.

However, the correct path delimiter on a Windows machine is "\", and since
this is an escape character in many interpretters and compilers, it needs
to be "escaped" itself with a preceeding "\". If you try using "/" on a
regular command prompt (ie NOT cygwin) you will likely receive an error
because it is recognized as a "switch" specifier.

Quote:
> Also, Apache & PHP are installed on
> a seperate drive than ipconfig.. I don't assume this would make a
> difference as they're both run under the same priviledges from the
> Administrator account and the php.ini is in my C: drive as well.. Apache &
> PHP are under D:/Apache/ and D:/Apache/PHP/ and my Docroot is also on my
> D: drive..

Naw, no matter. You can even create a drive mapped to a folder on another
drive, such as "M:\ ---> C:\MyWebStuff" and run everything from there,
which is considered by some as more secure because it removes _some_ of the
possibility of directory traversal. "../../../"

Quote:
> When adding either of your scripts to my task scheduler, how exactly do
> they
> work?  I don't see anything within either of your scripts that would send
> this information to my Linux remote server.. Only that they execute the
> ipconfig locally and print it out, assuming I'd went to it with a browser
> (which only returns 0.0.0.0 as an output)..

Well, all those scripts do is spit out a number. What you probably really
want to do with the number is send it to your server, something like this:

$checksum = MD5("mysecretxxxcode".$address);

        urlencode($address).
        "&checksum=".
        urlencode($checksum));

Then you have to write a script that receives the address and does something
with it.

<?
        if (MD5("mysecretxxxcode".$address) != $checksum)
        {
                exit();
        } else {

                $fp = fopen("address.txt","w");
                fwrite ($fp, $address);
                fclose($fp);
        }
?>

Best,

- --
Waitman Gobble         EMK Design     Buena Park, California

Public Key                          http://pgp.emkdesign.com
Find an example                    http://freakinexample.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE97sxtlkBqm2sl6RIRAhR8AKCD2a98I8BCdj9ZytKzNDSU7j5XDwCglnkC
7MuU+33eRbB7K6R/t7Man+0=
=XthB
-----END PGP SIGNATURE-----



Mon, 23 May 2005 11:46:59 GMT  
 local/remote script question
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quote:

> So on the Windows machine, you have a script that has this line:

> readfile ("http://remote.com/getipaddr.php");

> On the remote Linux machine, getipaddr.php could look like this:

> $ip = $_SERVER["REMOTE_ADDR"];
> echo "<p>Your remote IP address is $ip </p>";
> $fp = fopen ("myipaddr.htm", "w");
> fputs ($fp, "<META name=\"Expires\" content=\"" .
>             gmdate("D, d M Y H:i:s") . " GMT> \n");
> fputs ($fp, "<p>Last I checked, my IP adress was ".
>             "<a href=\"http://". $ip ."/\"</a></p> \n");
> fclose ($fp);
> echo "<p>File <tt>myipaddr.htm</tt> regenerated successfully </p>";

> Then give your friends this URL:

> http://remote.com/myipaddr.htm

I agree this is likely a better choice, just make sure:

1) only your machine can ask for the getipaddr.php script

2) you aren't going out through a proxy

3) you aren't on a multi-homed system or satellite/dialup mess.

- --
Waitman Gobble         EMK Design     Buena Park, California

Public Key                          http://pgp.emkdesign.com
Find an example                    http://freakinexample.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE97tIKlkBqm2sl6RIRAgsBAKCqi/aD26TUFjtMGvbKqJU9vBlg/QCgomnd
9cpRyzRn+hWRnCY5mjz3WfQ=
=CSq+
-----END PGP SIGNATURE-----



Mon, 23 May 2005 12:10:56 GMT  
 local/remote script question

: Well, you need to call the php executable and send the script filename as
: the first argument, like
:
: PROMPT> c:\php\php.exe c:\scriptlocation\ipaddr.php
:
: if you use the -q option it won't print any header information (probably
: what you want to do).
:
: PROMPT> c:\php\php.exe -q c:\scriptlocation\ipaddr.php
:
: <snip>

====

Thanks again Waitman.. I'll fiddle around with it the next day or so and see how
it works.. I appreciate all the details and code examples.. You've been a great
help..

Take care.. peace..
eriol



Mon, 23 May 2005 14:58:45 GMT  
 local/remote script question


Quote:

> I agree this is likely a better choice, just make sure:

> 1) only your machine can ask for the getipaddr.php script

Or there is some authentication...

Quote:
> 2) you aren't going out through a proxy

But then the whole exercise doesn't make sense...  If he is going
out through a proxy, it is highly likely that his computer will
not be accessible from the Internet.  It is still possible his
computer has a public IP address but is connected through a proxy,
but in my experience this is a relatively rare setup...

Cheers,
NC



Tue, 24 May 2005 10:08:33 GMT  
 local/remote script question

Quote:

> How does the script on my remote linux server (remote.com for
> example) get the information of my local IP from my WinXP Pro
> (local.com for example)?

It doesn't.  Apache does, because it receives the IP packet...

Quote:
> Neither machine are on the same network..

As a matter of fact, they ARE on the same network.  This network
is called the Internet...  Unless, of course your XP machine is
sitting on a private network and has a private IP address in one
of the following blocks:

10.0.0.0 through 10.255.255.255
172.16.0.0 through 172.31.0.0
192.168.0.0 through 192.168.255.255

But then, it is not going to be accessible from the Internet
whatever you do...

Anyway, I just put the script (with a few minor changes) up
to my Web site:

http://ncbase.com/getipaddr.php

The HTML file it generates will be accessible as:

http://ncbase.com/myipaddr.htm

Check it out (just call it from your machine without using
any PHP and see if it points you back to your machine) and
let me know if you still have a problem.

Cheers,
NC



Tue, 24 May 2005 10:11:00 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Web server: local VS remote...script not interpreted

2. Embedding - Local dictionaries for local scripts

3. local IP script question..

4. Remote/local VRMl viewing via Netscape

5. UDP recvfrom seems to report local not remote address (bug, f luke , documentation error)

6. UDP recvfrom seems to report local not remote address (bug, fluke , documentation error)

7. ftpmirror -local to remote?

8. Singleton COM local/remote server?

9. Remote script execution with Python ...

10. remote scripting

11. Expect Script - run remote commands

12. Anyone used WSH for remote scripting on WinXP?

 

 
Powered by phpBB® Forum Software