johnnys Posted June 12, 2014 Share Posted June 12, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/289125-changing-network-settings/ Share on other sites More sharing options...
kicken Posted June 12, 2014 Share Posted June 12, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/289125-changing-network-settings/#findComment-1482532 Share on other sites More sharing options...
johnnys Posted June 12, 2014 Author Share Posted June 12, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/289125-changing-network-settings/#findComment-1482535 Share on other sites More sharing options...
kicken Posted June 12, 2014 Share Posted June 12, 2014 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' buttonYou 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. Quote Link to comment https://forums.phpfreaks.com/topic/289125-changing-network-settings/#findComment-1482537 Share on other sites More sharing options...
johnnys Posted June 12, 2014 Author Share Posted June 12, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/289125-changing-network-settings/#findComment-1482546 Share on other sites More sharing options...
Ch0cu3r Posted June 12, 2014 Share Posted June 12, 2014 I realise I could install a local server on each laptop but not ideal. Just install PHP on all laptop and run your app of off PHP's internal server. Quote Link to comment https://forums.phpfreaks.com/topic/289125-changing-network-settings/#findComment-1482548 Share on other sites More sharing options...
Solution kicken Posted June 12, 2014 Solution Share Posted June 12, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/289125-changing-network-settings/#findComment-1482553 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.