setip.php:
<?php
$IP_Addr = $_GET['ip'];
$NetMask = $_GET['ip2'];
$NetWork = $_GET['ip3'];
$Broad = $_GET['ip4'];
$DNS = $_GET['dns1'];
$cmd="sh /var/www/cgi-bin/ipset.sh ".escapeshellarg($IP_Addr)."".escapeshellarg($NetMask)."".escapeshellarg($NetWork)."".escapeshellarg($Broad)."".escapeshellarg($DNS);
exec("$cmd");
示例输入: ip = 10,ip2 = 20,ip3 = 30,ip4 = 40,dns1 = 10
ipset.sh:
#!/bin/bash -x
echo "IPADDR=$1" >>/etc/sysconfig/network-scripts/ifcfg-eth0
echo "NETMASK=$2" >>/etc/sysconfig/network-scripts/ifcfg-eth0
echo "NETWORK=$3" >>/etc/sysconfig/network-scripts/ifcfg-eth0
echo "Broadcast=$4" >>/etc/sysconfig/network-scripts/ifcfg-eth0
echo "DNS=$5" >>/etc/sysconfig/network-scripts/ifcfg-eth0
导致ifcfg-eth0:
IPADDR=1020304010
NETMASK=
NETWORK=
BROADCAST=
DNS=
如何正确传递参数?
答案 0 :(得分:1)
解决,在参数之间添加空格。
<?php
$IP_Addr = $_GET['ip'];
$NetMask = $_GET['ip2'];
$NetWork = $_GET['ip3'];
$Broad = $_GET['ip4'];
$DNS = $_GET['dns1'];
$cmd="sh /var/www/cgi-bin/ipset.sh ".escapeshellarg($IP_Addr)." ".escapeshellarg($NetMask)." ".escapeshellarg($NetWork)." ".escapeshellarg($Broad)." ".escapeshellarg($DNS);
exec("$cmd");