LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-19-2006, 09:56 AM   #1
Richtown
Member
 
Registered: Apr 2006
Location: Portsmouth
Distribution: CentOS & Ubuntu
Posts: 49

Rep: Reputation: 15
Running iptables from PHP


Hi all,

Running Apache 2, i have a php webpage and i want to be able to enter in 192.168.1.1 in a field press a submit button. Then when i press it i want to be able to ALLOW or BLOCK the ipaddress using iptables.

using BASH the command would be iptables -A INPUT -s 192.168.1.1 -P ICMP -J DROP

i want to be able to do this in php i save the 192.168.1.1 or any other address as a variable $ip_address and import it into the following code?

<?php
echo exec('iptables -A INPUT -s $ip_address -j DROP');
?>




im not sure if this is the correct code, i want to be able to block or allow it then display the results on the wedpage.

the reason i am doing this is for a project and cannot be done any other way!

could someone shed some light i have spent hours on the web searching how to do this and with no luck, this is a last resort and would really appreciate the help, if offered.

kind regards
Rich
 
Old 04-20-2006, 07:52 AM   #2
Spudley
Member
 
Registered: Mar 2003
Location: Berkshire, England.
Distribution: SuSE 10.0
Posts: 299

Rep: Reputation: 32
The code you specified looks okay to me at first glance (I don't know much about IP tables, tho), but you will need to use double-quotes for your string if you want to include a $variable within it.

Hope that helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
running iptables from php rookiepaul Linux - Security 20 03-29-2006 09:28 PM
IPTABLES is running ? How? aurelio26 Linux - Newbie 7 11-20-2004 02:30 AM
Running nat with Iptables muppski Linux - Networking 1 11-10-2004 05:00 AM
php and iptables hkerssies Programming 3 10-22-2003 03:14 PM
Iptables with gShield running over it Belyle Linux - Newbie 3 04-17-2003 08:37 AM


All times are GMT -5. The time now is 08:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration