Jump to content

Changing Network Settings


johnnys
Go to solution Solved by kicken,

Recommended Posts

Hi,

 

I'm not sure if this is possible, however I'm sure somebody will be able to point me in the right direction. Relativley new to php here.

 

I would like to write a small app that will change my IP/Subnet Mask/Gateway depending on a selection made from a dropdown list. I will have a tota; of 50 different IP settings & drop downs (each drop down will represent a different location)

 

I have yet to start writing the app, just on paper so far - can this be done?

 

I have seen examples of batch scripts like the one below that work, would I need to incorporate something like this into my php?

netsh int ipv4 set address name="Local Area Connection" source=static address=10.127.86.25 mask=255.255.255.240 gateway=10.127.86.30

This is just a personal project, I'm trying to further my knowledge!

 

Thanks

 

J

Link to comment
Share on other sites

I have seen examples of batch scripts like the one below that work, would I need to incorporate something like this into my php?

netsh int ipv4 set address name="Local Area Connection" source=static address=10.127.86.25 mask=255.255.255.240 gateway=10.127.86.30

 

Yes, you'd just have to build the appropriate netsh command(s) to do what you want and then run them using exec. You'd have to make sure that the user your PHP script is being run as has the necessary permissions to execute those commands.

 

Out of curiosity, why do you want to dynamically change your IP settings like this?

Link to comment
Share on other sites

Thank you kicken,

 

I now have a rough idea of what I should be doing.

 

So, I would require 50 x netsh commands for each of the 50 different network configs. Can I add all these commands in the same batch file, and call them individually within my php?

 

The reason I want to change them is because I work as a network tech, and this involves working in various physical locations/buildings. Each location has a different router/switch and each has it's own network configs. Due to network security, IPs need to be entered static in order to access some of the switch configs.

 

If I could get this working it would be a great help for our team, and I think it would be a nice way to better my understanding of PHP.

 

I basically want to design a single html page, with a search large bar. User enters the location of where they are working, and the IP settings they shoud be using pops up. They then click 'confirm' to set these on their machine. I'd also like a 'reset' button,

 

Do you think this is achievable, or is there a better/more efficient way?

 

Thanks again,

 

J

Link to comment
Share on other sites

So, I would require 50 x netsh commands for each of the 50 different network configs. Can I add all these commands in the same batch file, and call them individually within my php?

You don't need 50 different commands, just use some variables to enter in the appropriate information for each site. Eg:

<?php
$sites = array(
   'Location1' => array(
      'ip' => '192.168.0.2'
      , 'netmask' => '255.255.255.0'
      , 'gateway' => '192.168.0.1'
    )
    , 'Location2' => array(
      'ip' => '10.100.10.1'
      , 'netmask' => '255.255.0.0'
      , 'gateway' => '10.100.1.1'
    )
    /// more
); 

//Do something to find the right settings
$site = $sites[$_GET['siteName']];
$cmd = sprintf('netsh int ipv4 set address name="Local Area Connection" source=static address=%s mask=%s gateway=%s', $site['ip'], $site['netmask'], $site['gateway']);
exec($cmd);

I basically want to design a single html page, with a search large bar. User enters the location of where they are working, and the IP settings they shoud be using pops up. They then click 'confirm' to set these on their machine. I'd also like a 'reset' button

You can't have it automatically change the settings of a client machine, only the server machine. If you're using a locally installed server then that'd work because the client and server are the same but if they are accessing a hosted website then the best you could do is generate a .bat file for them to download and run.
Link to comment
Share on other sites

Thanks again kicken,

 

That's a great help to me.  

 

I was planning on running this as an offline app on each of the client laptops (there being only 3). I completely overlooked that fact that the php won't work unless this app is hosted on a server (which we won't have access to unless we change the IP settings - making the app pointless!). I realise I could install a local server on each laptop but not ideal.

 

Plan B..!

 

Thanks

Link to comment
Share on other sites

  • Solution

If the settings for each location and # of locations don't change frequently I would probably just make a single .bat file that they can run and just select an environment.

 

Eg:

@echo off

echo [1] Site 1
echo [2] Site 2
echo [3] Site 4
SET /p LOC=Enter your location: 

GOTO :Loc%LOC%

:Loc1
echo netsh for site1...
GOTO :EOF

:Loc2
echo netsh for site2...
GOTO :EOF

:Loc3
echo netsh for site3...
GOTO :EOF
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.