Windows Environment Variable Extraction to HTML / WEB

We are making a simple HTML website.
We need to extract Windows Environment variables (Ie the ones set is Computer - Properties)
The variable we have set at dos level is called storename
We would also like to retrieve the IP Address and Default gateway of the PC
If we need to store these in environment variables too we will
Thanks in advance
Wizard_ITMDAsked:
Who is Participating?
 
Richard QuadlingConnect With a Mentor Senior Software DeveloperCommented:
If you are using PHP, then ...

<?php
exec('ipconfig', $a_IPConfig);
foreach($a_IPConfig as $s_ConfigLine)
      {
      if (preg_match('`(IP Address|Default Gateway)[^\d]*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})`sim', $s_ConfigLine, $a_Matches))
            {
            $s_Var = str_replace(' ', '_', $a_Matches[1]);
            $$s_Var = $a_Matches[2];
            }
      }

echo 'The storename is ', (isset($_ENV['storename']) ? $_ENV['storename'] : 'undefined'), PHP_EOL;
echo 'The IP Address is ', $IP_Address, PHP_EOL;
echo 'The Default Gateway is ', $Default_Gateway, PHP_EOL;
?>

for me, results in ...

The storename is undefined
The IP Address is 10.0.0.19
The Default Gateway is 10.0.0.9

If I set the storename to Bob's Shack of Tools

I get ...

The storename is Bob's Shack of Tools
The IP Address is 10.0.0.19
The Default Gateway is 10.0.0.9
0
 
Richard QuadlingSenior Software DeveloperCommented:
Do you want the CLIENT's computer name/IP address/gateway or the SERVER's computer name/IP address/gateway.

If it is the client's you want, then you will have to either ask them very nicely to enter it into a form or construct a java or activex app to get them (and there may be limits as to what you can get hold of).

Client side JS cannot access this info.

0
 
Richard QuadlingSenior Software DeveloperCommented:
The php solution can be easily adapted to any decent scripting language, but this still wouldn't give you CLIENT details, just server details.
0
 
Wizard_ITMDAuthor Commented:
Thanks qualding!!!
I uploaded a test page online containing the script you suggested and when browsing to the page i receive the following:
"Warning: exec() has been disabled for security reasons in /home/jay/public_html/index.php on line 13

Warning: Invalid argument supplied for foreach() in /home/jay/public_html/index.php on line 14
The storename is undefined The IP Address is The Default Gateway is "

the url of the page is "unusualsuspex.wmn.cc/index.php" if you want to take a look at source code
please help, i really need to get this working for monday!
Thanks in advance.
0
 
Richard QuadlingSenior Software DeveloperCommented:
The first error of "Warning: exec() has been disabled for security reasons in /home/jay/public_html/index.php on line 1", means that your ISP has disabled the ability for you to run external applications. Even such things as ipconfig.

This is a security setting made by the ISP and as such there is no work around using PHP. You could try using Perl (no idea what to code), but I suspect Perl has a similar mechanism on restrictions.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.