Graphical representation of Ping

Hello ,
I hope anyone can answer this question!!
I want to represent ping result of an IP address using matlab in a graphical way .i am pinging the IP:192.168.1.1 using this command : [status, result] = dos('ping 192.168.1.1', '-echo') and getting the following :
>>result
result =
Pinging 192.168.1.1 with 32 bytes of data:
Reply from 192.168.1.1: bytes=32 time=2ms TTL=64
Reply from 192.168.1.1: bytes=32 time=4ms TTL=64
Reply from 192.168.1.1: bytes=32 time=10ms TTL=64
Reply from 192.168.1.1: bytes=32 time=8ms TTL=64
Ping statistics for 192.168.1.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Is there any way to take the time variable that is inside the result and plot a graph so the output of the graph looks close to this :
TIME
10ms| *
8ms| *
6ms|
4ms| *
2ms| *
-|-----------------------> PING NUMBER
1st 2nd 3rd 4th# Item one
# Item two

4 comentarios

Daniel Shub
Daniel Shub el 8 de Mzo. de 2013
If you have an array of time values, could you make the plot look like you want?
tyler
tyler el 8 de Mzo. de 2013
yes , but i need to extract the time array from the result variable. do you have any idea how can i do that?
thanks for replying
tyler
tyler el 8 de Mzo. de 2013
Editada: tyler el 8 de Mzo. de 2013
Do i have to modify that expression?
because after i tried it i got this:
>> time = cellfun(@(y)(str2double(y{2})), regexp(result, '(time=)(\d[\d]*\.\d[\d]*)', 'tokens'))
time =
[]
I really appreciate your help Daniel :)
tyler
tyler el 8 de Mzo. de 2013
I also tried time[=<] instead of time=
but still getting an empty array for the time variable .
please advise :) Thanks

Iniciar sesión para comentar.

Respuestas (2)

Daniel Shub
Daniel Shub el 8 de Mzo. de 2013
Editada: Daniel Shub el 8 de Mzo. de 2013
You can extract the time data with a regular expression
time = cellfun(@(y)(str2double(y{2})), regexp(result, '(time[=<])([\d]*\.[\d]*)', 'tokens'))

8 comentarios

Jason Ross
Jason Ross el 8 de Mzo. de 2013
The ping command can also have "time<":
Reply from xyz.xy.xy.xy: bytes=32 time<1ms TTL=64
Daniel Shub
Daniel Shub el 8 de Mzo. de 2013
Same concept, slightly different regular expression. See edit.
Jason Ross
Jason Ross el 8 de Mzo. de 2013
Editada: Jason Ross el 8 de Mzo. de 2013
Yep. Just being pedantic so no data gets lost / missed. Otherwise tyler might be =< when things go missing.
Daniel Shub
Daniel Shub el 8 de Mzo. de 2013
Sorry Jason, I didn't realize that the comment was from you and not the OP.... There must be a more robust regular expression that would at least alert you to missed data. Maybe going between "time" and "ms".
No problem! If I was approached with this problem. I'd look at gathering the ping data in a format that didn't throw me this curve. I'd do one of the following
  • Try using NET.AddAssembly() with System.Net.NetworkInformation Ping class to make the ping and get the data back, skipping the regex altogether. This isn't my strongest skill so I'd likely end up banging around in the dark a little, then I'd eventually get my answer.
  • Use Perl and WMI to call into Win32_PingStatus and get the answers back that way, then call the Perl script from MATLAB. More indirect but I already have a pile of Perl scripts that do this, so it's not hard to modify (and MS's Scriptomatic tool can generate this for you in many different formats)
  • I'd pipe ping through find so I only get the "time" line:
ping hostname | find Reply
this will end up with four responses by default so I know something is fishy if I don't get that.
I'd also make sure to test things like pinging an unreachable host, and taking too long to reach a host.
Also, check the exit status -- I'd expect it to be non-zero if something goes wrong, and do the right thing (likely stop execution / error) if you can't find the host.
tyler
tyler el 9 de Mzo. de 2013
Hello Daniel,
Can you please tell me what is y inside the expression you wrote before ,i am trying different things to get an array with value ,but still nothing there.
thank you for your help
Tyler, Daniel's expression
time = cellfun(@(y)(str2double(y{2})), regexp(result, '(time[=<])([\d]*\.[\d]*)', 'tokens'))
is like writing
time = cellfun( @Convert_To_Number, regexp(result, '(time[=<])([\d]*\.[\d]*)', 'tokens') );
function result = Convert_To_Number( y )
result = str2double( y{2} );
end
That is, "y" is just the name of the variable used temporarily to perform the function.
Daniel Shub
Daniel Shub el 9 de Mzo. de 2013
My regexp is wrong. I don't use Windows so my ping returns something slightly different from yours. I didn't check to compare. My ping returns time as 20.2ms while yours does not have the decimal. The regexp looks for the word "time" followed by either = or <, and then followed by and number of digits (\d) a decimal point (\.) and en any number of digits. Since your ping does not return a decimal point just remove the \.[\d]* from the regexp. The y is just a fancy way of making cell fun work. Focus on getting regexp to return something meaningful.

Iniciar sesión para comentar.

Walter Roberson
Walter Roberson el 8 de Mzo. de 2013
Example:
plot(rand(1,10), 'LineStyle', 'none', 'Marker', '*')

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 8 de Mzo. de 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by