PHP调用系统命令修改IP,netmask,gateway,mac,dns
ip_contrl.php:
<?php
//include('header.php');
$ipaddr = $_POST['ipaddr'];
$netmask = $_POST['netmask'];
$gateway = $_POST['gateway'];
$mac = $_POST['mac'];
$dns1 = $_POST['dns1'];
$dns2 = $_POST['dns2'];
//echo "ipaddr=$ipaddr;netmask=$netmask<br>";
if( $ipaddr && $netmask && $gateway && $mac && $dns1 && $dns2 )
{
system("./ip/changeip 1 $ipaddr $netmask $gateway $mac $dns1 $dns2");
echo "<script type='text/javascript'>
alert( '网络配置成功!' );
window.location.href = 'service_manage.php?id=2';
</script>";
}
else
{
exec("ifconfig eth0", $res);
$str = explode( "HWaddr ",$res[0] );
$macaddr = $str[1]; //mac地址
//echo "str[1]=".$str[1]."<br>";
$s = explode( "addr:",$res[1] );
$s1 = explode( " Bcast:",$s[1] );
$ipaddr = $s1[0]; //ip地址
//echo "s1[0]=".$s1[0]."<br>";
$s2 = explode( "Mask:",$s1[1] );
$netmask = $s2[1]; //子网掩码
//echo "s2[1]=".$s2[1]."<br>";
}
?>
<script language="javascript">
function checkFormData()
{
if ( form1.ipaddr.value == "")
{
alert ( "IP地址不能为空!" );
form1.ipaddr.focus();
return false;
}
if ( form1.ipaddr.value.search (".*?((25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)\\.){3}(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d).*?") != 0 )
{
alert ( "IP格式不正确!" );
form1.ipaddr.focus();
return false;
}
if ( form1.netmask.value
相关文档:
1.1
exit() 函数输出一条消息,并退出当前脚本。
如果 status
是字符串,则该函数会在退出前输出字符串。
如果 status
是整数,这个值会被用作退出状态。退出状态的值在 0 至 254 之间。退出状态 255 由 PHP 保留,不会被使用。状态 0 用于成功地终止程序。
1.2
301 Moved Permanently 客户请求的文档在其他地方, ......
经典循环例子
<HTML>
<HEAD>
<TITLE>经典循环例子</TITLE>
</HEAD>
<BODY>
<?
for($counter = 1; $counter <= 6; $counter++)
//循环6次
{
print("<B& ......
例子. return() 函数的用法
<?php
function square ($num)
{
return $num * $num;
}
echo square (4); // outputs '16'.
?>
函数不能返回多个值,但为了获得简单的结果,可以返回一个列表。
例子. 返回一个数组以得到多个返回值
<?php
function small_numbe ......
php cli命令行模式是WIN下的一个SHELL,不需要APACHE的支持就能执行PHP脚本的脚本,并且是持续执行的。这些特点很容易利用来快速测试PHP脚本。今天就特意找来一些资料,整理了一下,权当复习。
D:\AppServ\php5>php -help
Usage: php [options] [-f] <file> [--] [args...]
&nbs ......