|
Hi C# Guru's,
i have recently written a command line C# app that uses psexec to run Netstat on remote machines and sends the results to a text file, it works ok...ish.
firstly, even though i have set the process to psi.UseShellExecute = false and psi.CreateNoWindow = true it still pops up a command window - any idea how i stop this?
secondly, even though it sends most of the output to the text file it cuts it off short, i have used the below code TNA.
while(p.StandardOutput.EndOfStream == false)
{
sw.Write(p.StandardOutput.ReadToEnd());
p.WaitForExit();
sw.Flush();
}
the bottom part of the output file looks like:
TCP 172.17.134.138:80 172.17.134.133:51076 TIME_WAIT 0
TCP 172.17.134.138:80 172.17.134.133:52450 TIME_WAIT 0
TCP 172.17.134.138:80 1
any ideas on how to get the full output?
Many Thanks,
Phil
|
|
|
|
|
Hi,
your code looks only so so, with a loop, several ReadToEnd and a flush.
assuming you save all incoming text to a file, there is no need to catch it while the netstat app is still running, so simplify your code to first wait for netstat to exit, then wait 500 msec to make sure everything has settled, then just once read all its output; assuming you close the output stream (or use a using statement) there is no need to flush either.
|
|
|
|
|
Hi,
thanks for post. i'm still a beginner at this...
how would i do what you suggested?
many thanks,
Phil
|
|
|
|
|
p.WaitForExit();
Thread.Sleep(500);
string s=p.StandardOutput.ReadToEnd();
File.WriteAllText(filepath, s);
|
|
|
|
|
Hi Luc,
thanks for your speedy reply.... it still doesn't work!
i still get the same result, it cuts of some of the output.
when i run psexec manually it does give some output and then pauses for the server to reply with more data. i think this is the point where it cuts out.
i'm open for any more suggestions!
many thanks,
Phil
|
|
|
|
|
is it repeatable, i.e. does it always produce the exact same output?
if so, can you show the output?
could it be that the target app launches yet another app, whose output is exactly what gets lost?
|
|
|
|
|
hi,
yes, the output is always the same.
this is the output:
Active Connections
Proto Local Address Foreign Address State PID
TCP 0.0.0.0:80 0.0.0.0 LISTENING 4
TCP 0.0.0.0:135 0.0.0.0 LISTENING 688
TCP 0.0.0.0:445 0.0.0.0 LISTENING 4
TCP 0.0.0.0:3389 0.0.0.0 LISTENING 1156
TCP 0.0.0.0:49152 0.0.0.0 LISTENING 392
TCP 0.0.0.0:49153 0.0.0.0 LISTENING 872
TCP 0.0.0.0:49154 0.0.0.0 LISTENING 928
TCP 0.0.0.0:49155 0.0.0.0 LISTENING 496
TCP 0.0.0.0:49157 0.0.0.0 LISTENING 1280
TCP 0.0.0.0:66258 0.0.0.0 LISTENING 488
TCP 172.22.139.171:139 0.0.0.0 LISTENING 4
TCP 172.22.139.171:50362 172.16.66.85:3389 ESTABLISHED 7296
TCP 172.22.139.171:50774 172.16.66.85:389 CLOSE_WAIT 4984
TCP 172.22.139.171:50962 172.16.65.75:2020 ESTABLISHED 2304
TCP 172.22.139.171:51323 172.16.66.136:2528 ESTABLISHED 2536
TCP 172.22.139.171:51377 194.34.15.37:139 ESTABLISHED 4
TCP 172.22.139.171:51523 172.16.66.86:135 TIME_WAIT 0
TCP 172.22.139.171:51527 172.16.66.86:139 TIME_WAIT 0
TCP 172.22.139.171:51530 172.16.66.89:135 TIME_WAIT 0
TCP 172.22.139.171:51536 172.16.66.89:139 TIME_WAIT 0
TCP 172.22.139.171:51539 172.16.66.86:135 ESTABLISHED 688
TCP 172.22.139.171:51540 172.16.66.86:2007 ESTABLISHED 4132
TCP 172.22.139.171:51543 172.16.66.86:139 ESTABLISHED 4
TCP 172.22.139.171:58467 172.16.66.86:1025 ESTABLISHED 2536
TCP 172.22.139.171:60942 172.16.66.85:1025 ESTABLISHED 476
TCP 172.22.139.171:60945 172.16.66.85:1025 ESTABLISHED 2536
TCP 172.22.139.171:61196 172.16.227.140:139 ESTABLISHED 4
TCP 172.22.139.171:62671 172.16.66.92:139 ESTABLISHED 4
TCP 172.22.139.171:66301 172.16.160.12:5061 ESTABLISHED 476
TCP 172.22.139.171:66322 172.16.130.91:4204 ESTABLISHED 2536
TCP 172.22.139.171:66586 172.16.66.85:389 CLOSE_WAIT 4984
TCP 172.22.139.171:66923 172.16.194.31:139 ESTABLISHED 4
TCP 172.22.139.171:65420 172.16.66.85:389 CLOSE_WAIT 4984
TCP 172.22.139.171:65480 172.16.66.85:389 CLOSE_WAIT 4984
TCP [::]:80 [::] LISTENING 4
TCP [::]:135 [::] LISTENING 688
TCP [::]:445 [::] LISTENING 4
TCP [::]:3389 [::] LISTENING 1156
TCP [::]:49152 [::] LISTENING 392
TCP [::]:49153 [::] LISTENING 872
TCP [::]:49154 [::] LISTENING 928
TCP [::]:49155 [::] LISTENING 496
TCP [::]:49157 [::] LISTENING 1280
TCP [::]:66258 [::] LISTENING 488
TCP [::1]:445 [::1]:51544 ESTABLISHED 4
TCP [::1]:51544 [::1]:445 ESTABLISHED 4
UDP 0.0.0.0:123 *:* 1056
UDP 0.0.0.0:500 *:* 928
UDP 0.0.0.0:4500 *:* 928
UDP 0.0.0.0:5355 *:* 1156
UDP 0.0.0.0:6004 *:* 2536
UDP 127.0.0.1:54417 *:* 2536
UDP 127.0.0.1:55932 *:*
|
|
|
|
|
Hi All,
Is there any way to know what is my public IP??
example say my public IP is 202.214.215.12
How would I know my IP??
Please dont say ipconfig.
Thanks,
Sunil G.
|
|
|
|
|
Yes, there is a way, you could ask your NAT device what its (and therefore also your) public IP address is.
|
|
|
|
|
Can u give me some idea how to do it??
|
|
|
|
|
Hi,
you could use UPnP of your router
bye
|
|
|
|
|
MonoTorrent can do it (UPnP and NAT-PMP), Windows has stuff for this build-in as well but it's not very reliable (IIRC it depends on a service which can be disabled), and you could read my article (it's a little old though)
|
|
|
|
|
Try a Google search, there are quite a few sites that can find this information for you. I think one of them may even be called "whatsmyip.com".
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
IMO the only reliable way is by asking the external world. Here[^] is one of many sites that may help.
|
|
|
|
|
|
That does not help me at all, I did not have the problem, and I did offer a solution here[^].
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
modified on Friday, June 10, 2011 8:43 PM
|
|
|
|
|
My router registers at dyndns.org, so I can query the IP address for my dyndns name.
|
|
|
|
|
Hi , have a good day ,
I have an Indicator Weight connect to COM port on My Pc ,
When I press the "Print Button" on the Indicator it sent weight to the Com Port ,
And I receive the data by this events :
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
TxtOutPut.Text = serialPort1.ReadExisting();
}
So far so good ,
The Only problem I had is that When I press The "Print Button" on the indicator "
The DataReceived Firing 5 times , Before all the data sent , For Example :
The indicator Show The Weight on it's screen Like "US,NT 4.590 KG"
so When I press "Print Button" On the Indicator its Sent :
1) US,NT --- DataReceived Firing ,
2) Space --- DataReceived Firing ,
3) 4.590 --- DataReceived Firing ,
4) Space --- DataReceived Firing ,
5) "\r\n" --- DataReceived Firing ,
I think It's Must Sent the Weight as a whole , ( as Other Indicators Works ! )
Any Suggest Would be Appreciated !
I know nothing , I know nothing ...
|
|
|
|
|
Hi,
you should use the "ReadLine" method instead since it reads the response until it receives a "NewLine" (\n).
Try:
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
TxtOutPut.Text = serialPort1.ReadLine();
}
|
|
|
|
|
Wow !
Thank you so much , Sir , Very Smart replay !
Here is (5)
P.S:
How I could not realize that ,
I know nothing , I know nothing ...
|
|
|
|
|
The alternative is to wait a while inside the DataReceived handler, so more/all data can come in before you get it all. Say 100 msec.
Or, if you need it fully event driven, start a timer in DataReceived, and read in the Tick handler (don't forget to stop the timer again).
|
|
|
|
|
Nice , I Will try the 100 Msc Things , I think it worth
Since I found more easy than the ReadLine() function ,
Thank you Sir ,
I know nothing , I know nothing ...
|
|
|
|
|
Stark DaFixzer wrote: P.S:
How I could not realize that
By reading the documentation on MSDN[^].
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Hi.
I'm writing my own filter in C++ and C#.
How i can change audio format ac-3 to lpcm , during playing video/audio ?
How i can do dinamic format change?
Can anybody help me ?
Thanks.
We are haven't bug,just temporarily undecided problems.
|
|
|
|
|
Hi all,
I have used many time C++ DLL which export functions in C#.net project by using DLLimport. Now i have a C++ DLL which exports classes, so can any body suggest me how can i use C++ DLL classes in my C# project.
Thanks
Bankey
|
|
|
|