Windows Azure Cloud Storage ermöglicht es Ihnen bereits ab 0,10€ pro GB/Monat die Vorteile der Cloud zu nutzen.
Willkommen bei dotnet-snippets.de! Snippet hinzufügen Login Registrieren
Snippets in der Datenbank: 1551 | Anzahl registrierter User: 1841 | Besucher online: 197
Hauptmenü
Home
Top Ten
Zufälliger Snippet
FAQs
.NET Community
dotnet-forum.de
dotnet-kicks.de
Social

RSS Feeds
Rss Alle Snippets
Rss C#
Rss VB.NET
Rss C++
Rss ASP.NET
Partner
Member of Microsoft Community Leader/Insider Program (CLIP)

IP-Addressen aus Registry auslesen


Autor: Volker Steitz
Sprache: VB.NET
Bewertung:
8.56 (2 votes)
Anzahl der Aufrufe: 13034
  
Kick it on dotnet-kicks.de  

Beschreibung:

Manchmal ist es notwendig, dass man die in der Registry eingetragenen IP-Addressen aller vorhandenen Adapter auslesen muss.

Das nachfolgenden Snippet ermöglicht dies und gibt die Daten als String (xxx.xxx.xxx.xxx) zurück


Abgelegt unter: Netzwerk, IP, Rwegistry.



Visual Basic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    Public Shared Function GetIPAddresses(ByVal adapter As String) As String()
        Dim oBuffer As New ArrayList()
        Dim sInterface As String
        Dim arrInterface As String()
        Dim sIPAddress As String
        Dim arrIPAddress As String()
        Dim bDHCP As Boolean
        Dim strBaseKey As String = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"
        Dim objRootKey As Microsoft.Win32.RegistryKey
        Dim objKey As Microsoft.Win32.RegistryKey
        Dim Registry As Microsoft.Win32.Registry = Nothing



        objRootKey = Registry.LocalMachine.OpenSubKey(strBaseKey, False)

        If objRootKey Is Nothing Then
            Return oBuffer.ToArray(Type.GetType("System.String"))
            Exit Function
        End If
        arrInterface = objRootKey.GetSubKeyNames()

        For Each sInterface In arrInterface



            objKey = Registry.LocalMachine.OpenSubKey(strBaseKey & sInterface & "\", False)
            ''Make sure that we got a key!
            If Not (objKey Is Nothing) Then
                'Pruft ob DHCP eingeschaltet ist
                'wenn nicht, werden alle vorghanden IP addressen geladen
                bDHCP = objKey.GetValue("EnableDCHP", False)
                If bDHCP Then
                    'Einzelne IP address auslesen
                    sIPAddress = objKey.GetValue("DhcpIPAddress", "")
                    'Pruefung ob gueltige IP
                    If (sIPAddress.Length > 0) And (sIPAddress <> "0.0.0.0") Then
                        oBuffer.Add(sIPAddress)
                    End If
                Else

                    For Each oName As Object In objKey.GetValueNames
                        'MsgBox(oName.ToString())
                        If oName.ToString.ToLower = "ipaddress" Then
                            'Lesen und array erstellen
                            arrIPAddress = objKey.GetValue(oName, "")
                            'Pruefung ob gueltige IP
                            For Each sIPAddress In arrIPAddress
                                If (sIPAddress.Length > 0) And (sIPAddress <> "0.0.0.0") Then
                                    oBuffer.Add(sIPAddress)
                                End If
                            Next
                        End If
                    Next
                End If
            End If
        Next
        Registry.LocalMachine.Close()

        Return oBuffer.ToArray(Type.GetType("System.String"))

    End Function
Sie haben Fragen zu diesem Snippet oder brauchen Hilfe bei der .NET Entwicklung?
Freundliche und kompetente Entwickler helfen Ihnen gern weiter im Forum für .NET Entwicklung.



Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)



schlecht sehr gut
1 2 3 4 5 6 7 8 9 10
Nur angemeldete User können Snippets bewerten.