IP Adressen die auf mein PC zugreifen auflisten?

  • VB.NET

Es gibt 7 Antworten in diesem Thema. Der letzte Beitrag () ist von Pixxxas.

    Aber selbstverständlich.

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.Runtime.InteropServices
    2. Public Class Form1
    3. Public Structure MIB_TCPROW_OWNER_PID
    4. Dim dwState As Integer
    5. Dim dwLocalAddr As Integer
    6. Dim dwLocalPort As Integer
    7. Dim dwRemoteAddr As Integer
    8. Dim dwRemotePort As Integer
    9. Dim dwOwningPid As Integer
    10. End Structure
    11. Private Const ERROR_BUFFER_OVERFLOW As Short = 111
    12. Private Const ERROR_INVALID_PARAMETER As Short = 87
    13. Private Const ERROR_NO_DATA As Short = 232
    14. Private Const ERROR_NOT_SUPPORTED As Short = 50
    15. Private Const ERROR_SUCCESS As Short = 0
    16. '
    17. Private Const MIB_TCP_STATE_CLOSED As Short = 1
    18. Private Const MIB_TCP_STATE_LISTEN As Short = 2
    19. Private Const MIB_TCP_STATE_SYN_SENT As Short = 3
    20. Private Const MIB_TCP_STATE_SYN_RCVD As Short = 4
    21. Private Const MIB_TCP_STATE_ESTAB As Short = 5
    22. Private Const MIB_TCP_STATE_FIN_WAIT1 As Short = 6
    23. Private Const MIB_TCP_STATE_FIN_WAIT2 As Short = 7
    24. Private Const MIB_TCP_STATE_CLOSE_WAIT As Short = 8
    25. Private Const MIB_TCP_STATE_CLOSING As Short = 9
    26. Private Const MIB_TCP_STATE_LAST_ACK As Short = 10
    27. Private Const MIB_TCP_STATE_TIME_WAIT As Short = 11
    28. Private Const MIB_TCP_STATE_DELETE_TCB As Short = 12
    29. Declare Function GetExtendedTcpTable Lib "IPHLPAPI.dll" (ByVal pTcpTable As IntPtr, ByRef dwTcpTableSize As Integer, ByVal bOrder As Boolean, ByVal ulAf As Integer, ByVal TCP_TABLE_CLASS As Integer, ByVal Reserved As Integer) As Integer
    30. Public Function GetExtendedTCPdata() As String()
    31. Dim AF_INET As Integer = 2
    32. Dim dwTcpTableSize As Integer
    33. Dim RetVal As Integer
    34. Dim ListofTcpRows As MIB_TCPROW_OWNER_PID
    35. Dim iNumberOfStructures As Integer
    36. Dim pStructPointer As IntPtr = IntPtr.Zero
    37. outputBox.Items.Clear()
    38. RetVal = GetExtendedTcpTable(pStructPointer, dwTcpTableSize, 1, AF_INET, 5, 0)
    39. pStructPointer = Marshal.AllocHGlobal(dwTcpTableSize)
    40. 'MessageBox.Show(dwTcpTableSize.ToString)
    41. RetVal = GetExtendedTcpTable(pStructPointer, dwTcpTableSize, 1, AF_INET, 5, 0)
    42. iNumberOfStructures = Math.Ceiling((dwTcpTableSize - 4) / Marshal.SizeOf(GetType(MIB_TCPROW_OWNER_PID)))
    43. For i = 0 To iNumberOfStructures - 1
    44. Dim pStructPointerTemp As IntPtr = New IntPtr(pStructPointer.ToInt32() + 4 + (i * Marshal.SizeOf(GetType(MIB_TCPROW_OWNER_PID))))
    45. 'Dim ListOfTcpRows As New List(Of MIB_TCPROW_OWNER_PID)
    46. ListofTcpRows = New MIB_TCPROW_OWNER_PID()
    47. ListofTcpRows = CType(Marshal.PtrToStructure(pStructPointerTemp, GetType(MIB_TCPROW_OWNER_PID)), MIB_TCPROW_OWNER_PID)
    48. If Not ((GetState(ListofTcpRows.dwState) = Nothing)) Then
    49. '
    50. 'Add the data to the ListView control
    51. ' Try
    52. On Error Resume Next
    53. With ListofTcpRows
    54. Dim p As Process = Process.GetProcessById(CStr(.dwOwningPid))
    55. Dim itemAdd As ListViewItem
    56. itemAdd = outputBox.Items.Add(CStr(.dwOwningPid))
    57. itemAdd.SubItems.Add(p.ProcessName)
    58. itemAdd.SubItems.Add(GetIpFromLong(.dwLocalAddr))
    59. itemAdd.SubItems.Add(CStr(GetTcpPortNumber(.dwLocalPort)))
    60. itemAdd.SubItems.Add(GetIpFromLong(.dwRemoteAddr))
    61. itemAdd.SubItems.Add(CStr(GetTcpPortNumber(.dwRemotePort)))
    62. If Not ((GetState(ListofTcpRows.dwState) = Nothing)) Then
    63. itemAdd.SubItems.Add(GetState(.dwState))
    64. Else
    65. itemAdd.SubItems.Add("Unknown")
    66. End If
    67. End With
    68. ' Catch
    69. 'MessageBox.Show("Error Occured, try again.")
    70. ' End Try
    71. '
    72. End If
    73. Next
    74. End Function
    75. Private Function GetIpFromLong(ByRef lngIPAddress As Integer) As String
    76. '
    77. Dim arrIpParts() As Byte = BitConverter.GetBytes(lngIPAddress)
    78. GetIpFromLong = CStr(arrIpParts(0)) & "." & CStr(arrIpParts(1)) & "." & CStr(arrIpParts(2)) & "." & CStr(arrIpParts(3))
    79. ''
    80. End Function
    81. Private Function GetTcpPortNumber(ByRef DWord As Integer) As Integer
    82. GetTcpPortNumber = DWord / 256 + (DWord Mod 256) * 256
    83. End Function
    84. Private Function GetState(ByRef lngState As Integer) As String
    85. '
    86. Select Case lngState
    87. Case MIB_TCP_STATE_CLOSED : GetState = "CLOSED"
    88. Case MIB_TCP_STATE_LISTEN : GetState = "LISTEN"
    89. Case MIB_TCP_STATE_SYN_SENT : GetState = "SYN_SENT"
    90. Case MIB_TCP_STATE_SYN_RCVD : GetState = "SYN_RCVD"
    91. Case MIB_TCP_STATE_ESTAB : GetState = "ESTAB"
    92. Case MIB_TCP_STATE_FIN_WAIT1 : GetState = "FIN_WAIT1"
    93. Case MIB_TCP_STATE_FIN_WAIT2 : GetState = "FIN_WAIT2"
    94. Case MIB_TCP_STATE_CLOSE_WAIT : GetState = "CLOSE_WAIT"
    95. Case MIB_TCP_STATE_CLOSING : GetState = "CLOSING"
    96. Case MIB_TCP_STATE_LAST_ACK : GetState = "LAST_ACK"
    97. Case MIB_TCP_STATE_TIME_WAIT : GetState = "TIME_WAIT"
    98. Case MIB_TCP_STATE_DELETE_TCB : GetState = "DELETE_TCB"
    99. Case Else : GetState = ""
    100. End Select
    101. ''
    102. End Function
    103. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    104. GetExtendedTCPdata()
    105. End Sub
    106. End Class


    Ich hab noch was ohne API gefunden:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.Net.NetworkInformation
    2. Imports System.Text
    3. Imports System.Net
    4. Public Class Form1
    5. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6. 'Retriving IP global properties
    7. Dim IPGproperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
    8. 'Retriving the TCP connections
    9. Dim connections As TcpConnectionInformation() = IPGproperties.GetActiveTcpConnections()
    10. For Each tcp As TcpConnectionInformation In connections
    11. 'Displaying TCP connection informations
    12. With lv.Items.Add(tcp.LocalEndPoint.Address.ToString & ":" & tcp.LocalEndPoint.Port)
    13. .SubItems.Add(tcp.RemoteEndPoint.Address.ToString & ":" & tcp.RemoteEndPoint.Port())
    14. .SubItems.Add(tcp.State.ToString())
    15. End With
    16. Next
    17. Dim connection As IPEndPoint() = IPGproperties.GetActiveTcpListeners()
    18. For Each tcp As IPEndPoint In connection
    19. 'Displaying TCP connection informations
    20. lv.Items.Add(tcp.Address.ToString & ":" & tcp.Port)
    21. Next
    22. End Sub
    23. End Class
    Für ein Mindestmaß an Rechtschreibung, Interpunktion und Majuskeln!
    Ok erst mal danke soweit für die Hilfe.
    Aber leider werden die Adressen nicht angezeigt die auf meine Datein zugreifen.

    Wollte eine Tool schreiben das z.b. bei COD MW2 verwenden hätte können.
    Wenn ich der Host bin greifen ja alle auf meine Server Dateien zu, und dann wenn ein Cheater im Spiel ist das ich "nur" seine IP Adresse Blocken muss damit er keine Verbindung mehr hat.
    Aber leichter gesagt als getan, ich weiß.....