[MonoDevelop] [HowTo] Executing Shell Commands...

Quandary quandary82 at hailmail.net
Sun Oct 24 03:47:03 EDT 2010


proc.StartInfo.FileName = "/sbin/iptables";

You should also try to read back the process exit code, such as 
EXIT_SUCCESS or EXIT_FAILURE.
To do it on bash: echo $?

If that won't work with system.diagnostics.process, you can try to 
DllImport popen from glibc

    #include <stdio.h>

        FILE *popen(const char *command, const char *type);

        int pclose(FILE *stream);

You can get a reference on how to use popen to read results from 
programs, such as a GDB disassembly from one of my aimbots here:
http://aimbots.net/urban-terror-cheats-linux/13863-release-cross-platform-urthack.html
Direct link:
http://www.mediafire.com/?jmvbxzl19a9


If you have too much time, you can also read the source of iptables and 
implement a netfilter API for Linux in C#, that is to say, writing your 
own firewall.

You can also try to use libiptc:
http://www.faqs.org/docs/Linux-HOWTO/Querying-libiptc-HOWTO.html 
<http://www.faqs.org/docs/Linux-HOWTO/Querying-libiptc-HOWTO.html#WHATIS>

On 10/20/2010 11:20 AM, raz3r wrote:
> I need to execute a list of iptables commands that are sent by Socket
> application. The Client is running on Windows and sends iptables commands
> (one by one), the Server (made with Mono) is running on Linux and has to
> execute each line of command that receive.
>
> Each command looks like:
>
> $IPTABLES...
>
> Before commands i send this line to set the variable:
>
> IPTABLES='iptables'
>
> I tryed with this code:
> .....
> 			while (true)
> 			{
> 				bytesread = 0;
> 				try
> 				{
> 					bytesread = clientStream.Read(message, 0, 4096);
> 				}
> 				catch
> 				{
> 					break;
> 				}
> 				if (bytesread == 0)
> 					break;
> 				//Executing: $IPTABLES COMMAND
> 				ASCIIEncoding encoding = new ASCIIEncoding();
> 				Console.WriteLine("Executing: "+encoding.GetString(message, 0,
> bytesread));
> 				System.Diagnostics.Process proc = new System.Diagnostics.Process();
> 				proc.EnableRaisingEvents = false;
> 				proc.StartInfo.FileName = ""; ????????????
> 				proc.StartInfo.Arguments = encoding.GetString(message, 0, bytesread);
> 				proc.Start();
> 				//SENDING OK
> 				string toSend = "OK";
> 				byte[] buffer = encoding.GetBytes(toSend);
> 				clientStream.Write(buffer, 0, buffer.Length);
> 				proc.Close();
> 			}
> .....
>
> What is this FileName parameter? I do not know how to configure this one...
> Can you help me?
>    

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monodevelop-list/attachments/20101024/178615a1/attachment-0001.html 


More information about the Monodevelop-list mailing list