using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Redirect
{
class Class1
{
[ DllImport("Kernel32.dll", SetLastError = true) ]
public static extern int SetStdHandle(int device, IntPtr handle);
[ DllImport("SayHello.dll") ]
public static extern void SayHello();
[STAThread]
static void Main(string[] args)
{
int status;
IntPtr handle;
FileStream fs;
StreamWriter sw;
fs = new FileStream("console.txt", FileMode.Create);
sw = new StreamWriter(fs);
sw.AutoFlush = true;
Console.SetOut(sw);
Console.WriteLine("This is a test of output via C#.");
handle = fs.Handle;
status = SetStdHandle(-11, handle);
SayHello();
}
}
}
public string ReadAll(MemoryStream memStream)
{
// Reset the stream otherwise you will just get an empty string.
// Remember the position so we can restore it later.
dynamic pos = memStream.Position;
memStream.Position = 0;
StreamReader reader = new StreamReader(memStream);
dynamic str = reader.ReadToEnd();
// Reset the position so that subsequent writes are correct.
memStream.Position = pos;
return str;
}
private static client = new AnonymousPipeClientStream(PipeDirection.In, server.ClientSafePipeHandle);
client.Flush();
не поддерживается Flush, если закоментить строки
Просто в шеле написал
iptables -t nat -D POSTROUTING -s '178.xxx.xxx.96/29' -o eth0 -j MASQUERADE
проверил, таки да!!! заработало именно так как надо.
Спасибо, очень выручили!