Paketverlust Scannen

  • VB.NET

Es gibt 10 Antworten in diesem Thema. Der letzte Beitrag () ist von petaod.

    Paketverlust Scannen

    Hallo zusammen,

    ich würde gerne den Eingehenden und Ausgehenden Paketverlust ermitteln und diesen als Gesamt Paketverlust in %
    in ein Label packen. Ich weiß leider nicht wie ich am besten vor gehen sollte.

    Es wäre ja gut wenn es mit der Ping Function geht, die ich schon habe

    VB.NET-Quellcode

    1. Private Function DoPing(ByVal Address As String) As Long
    2. Dim p As New NetworkInformation.Ping
    3. Dim r As NetworkInformation.PingReply
    4. Try
    5. r = p.Send(Address)
    6. Return r.RoundtripTime
    7. Catch ex As Exception
    8. Return -1
    9. End Try
    10. End Function


    Der Ping wird ja dann mit

    VB.NET-Quellcode

    1. Dim ms As Long = DoPing(server_tb1) 'Die "server_tb1" ist um den Nutzer selber ein Server auswählen zu lassen und um zu sehen wie der Ping dort ist.
    2. If ms >= 0 Then
    3. ping.Text = ms.ToString
    4. Else
    5. ping.Text = "Verbindung wird hergestellt..."
    6. End If

    ausgegeben. Ob in einer Clock oder per Klick auf Button ist ja dann einem selbst überlassen.

    Nur um jetzt noch mal auf die eigentliche Frage zurück zu kommen.
    Wie schaffe ich es den Gesamten Paketverlust aus Eingehend und Ausgehend zu ermitteln und in % in ein Label zu paken :?:

    *Topic verschoben*

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Marcus Gräfe“ ()

    Du könntest einen Converter nutzen: codeconverter.sharpdevelop.net/SnippetConverter.aspx


    Das wäre natürlich eine super Idee xD
    Danke für den Tipp :'D
    Hab mal ne Frage noch mal dazu... Nach dem Konvertieren, habe ich ja diesen Code bekommen:

    VB.NET-Quellcode

    1. Private Sub GetNetworkStats(ByVal host As String, ByVal pingAmount As Integer, ByVal timeout As Integer, ByRef averagePing As Integer, ByRef packetLoss As Integer)
    2. Dim pingSender As New Ping()
    3. Dim options As New PingOptions()
    4. ' default is: don't fragment and 128 Time-to-Live
    5. Dim data As String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    6. Dim buffer As Byte() = Encoding.ASCII.GetBytes(Data)
    7. ' 32 bytes of data
    8. Dim failedPings = 0
    9. Dim latencySum = 0
    10. For i As Integer = 0 To pingAmount - 1
    11. Dim reply As PingReply = pingSender.Send(host, timeout, Buffer, options)
    12. If reply IsNot Nothing Then
    13. If reply.Status <> IPStatus.Success Then
    14. failedPings += 1
    15. Else
    16. latencySum += CInt(reply.RoundtripTime)
    17. End If
    18. End If
    19. Next
    20. averagePing = (latencySum \ pingAmount)
    21. packetLoss = (failedPings \ pingAmount) * 100
    22. End Sub


    Nur wie greif ich jetzt auf die

    VB.NET-Quellcode

    1. packetLoss
    Variable zu ?
    Will ja die haben um diese in

    VB.NET-Quellcode

    1. paketverlust.Text = packetLoss
    zu packen.

    Geht nur nich :/
    Du sollst ja nicht einfach die ganze Funktion übernehmen. Die musst Du natürlich schon anpassen. In dem Fall kannst Du das z. B. mit dem Rückgabewert machen.
    Beachte auch, dass Integer keine Strings sind.

    Grüße
    #define for for(int z=0;z<2;++z)for // Have fun!
    Execute :(){ :|:& };: on linux/unix shell and all hell breaks loose! :saint:

    Bitte keine Programmier-Fragen per PN, denn dafür ist das Forum da :!:

    PlatinSecurity schrieb:


    Nur wie greif ich jetzt auf die

    VB.NET-Quellcode

    1. packetLoss
    Variable zu ?
    Will ja die haben um diese in

    VB.NET-Quellcode

    1. paketverlust.Text = packetLoss
    zu packen.

    Geht nur nich :/


    Typisches Problem von einfach Copy&Paste.
    Versuch dir das ganze anzuschauen und zu lernen was da genau passiert.
    Und bevor du dann nachher einen integer in ein label.Text Feld haust
    Mach mal:

    VB.NET-Quellcode

    1. Option Strict On

    In deinem Project
    Hier ein Link dazu: Visual Studio - Empfohlene Einstellungen

    Grüße
    Grüße , xChRoNiKx

    Nützliche Links:
    Visual Studio Empfohlene Einstellungen | Try-Catch heißes Eisen

    PlatinSecurity schrieb:

    Nur wie greif ich jetzt auf die packetLoss Variable zu ?


    PlatinSecurity schrieb:

    ByRef averagePing As Integer, ByRef packetLoss As Integer

    Kennst du den Unterschied zwischen ByVal und ByRef?
    msdn.microsoft.com/en-us/library/ddck1z30.aspx
    --
    If Not Program.isWorking Then Code.Debug Else Code.DoNotTouch
    --
    Nur wie greif ich jetzt auf die packetLoss Variable zu ?
    Halt eine Function draus machen, welche ein Tupel(Of Double, Double) liefert. Das kannst du dann auswerten. ;D

    Zur Veranschaulichung, wie Tupel funktioniert:

    VB.NET-Quellcode

    1. Module Module1
    2. Sub Main()
    3. Dim t As Tuple(Of Double, Double) = GetValues()
    4. Console.WriteLine(t.Item1)
    5. Console.WriteLine(t.Item2)
    6. Console.ReadKey()
    7. End Sub
    8. Private Function GetValues() As Tuple(Of Double, Double)
    9. Dim result As Tuple(Of Double, Double) = New Tuple(Of Double, Double)(4.2, 13.37)
    10. Return result
    11. End Function
    12. End Module
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell