Nslookup per determinare hostname

di il
21 risposte

21 Risposte - Pagina 2

  • Re: Nslookup per determinare hostname

    Scusa nel secondo combobox non si potrebbero avere i nomi dei pc invece che nuovamente gli ip?
    grazie
  • Re: Nslookup per determinare hostname

    Intendi nel primo, cioè quelli che hanno risposto al ping?
    
    Public Class Form1
        Private Const ping_timeout_ms As Integer = 500
        Private test(254) As Boolean
        Private host_name(254) As String
        Private bg2_completed As Boolean = False
        Private bg3_completed As Boolean = False
        Private bg4_completed As Boolean = False
        Private my_net As String
        Friend WithEvents BackgroundWorker1 As New System.ComponentModel.BackgroundWorker()
        Friend WithEvents BackgroundWorker2 As New System.ComponentModel.BackgroundWorker()
        Friend WithEvents BackgroundWorker3 As New System.ComponentModel.BackgroundWorker()
        Friend WithEvents BackgroundWorker4 As New System.ComponentModel.BackgroundWorker()
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim ip() As Byte = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList(0).GetAddressBytes()
            my_net = ip(0).ToString & "." & ip(1).ToString & "." & ip(2).ToString & "."
            BackgroundWorker1.RunWorkerAsync()
            BackgroundWorker2.RunWorkerAsync()
            BackgroundWorker3.RunWorkerAsync()
            BackgroundWorker4.RunWorkerAsync()
        End Sub
    
        Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
            For i As Integer = 1 To 253 Step 4
                If My.Computer.Network.Ping(my_net & i.ToString, ping_timeout_ms) Then
                    test(i) = True
                    Try
                        host_name(i) = System.Net.Dns.GetHostByAddress(my_net & i.ToString).HostName
                    Catch ex As Exception
                        host_name(i) = my_net & i.ToString
                    End Try
                Else
                    test(i) = False
                    host_name(i) = my_net & i.ToString
                End If
            Next
            While Not (bg2_completed And bg3_completed And bg4_completed)
                System.Threading.Thread.Sleep(100)
            End While
        End Sub
    
        Private Sub BackgroundWorker2_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork
            For i As Integer = 2 To 254 Step 4
                If My.Computer.Network.Ping(my_net & i.ToString, ping_timeout_ms) Then
                    test(i) = True
                    Try
                        host_name(i) = System.Net.Dns.GetHostByAddress(my_net & i.ToString).HostName
                    Catch ex As Exception
                        host_name(i) = my_net & i.ToString
                    End Try
                Else
                    test(i) = False
                    host_name(i) = my_net & i.ToString
                End If
            Next
            bg2_completed = True
        End Sub
    
        Private Sub BackgroundWorker3_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker3.DoWork
            For i As Integer = 3 To 251 Step 4
                If My.Computer.Network.Ping(my_net & i.ToString, ping_timeout_ms) Then
                    test(i) = True
                    Try
                        host_name(i) = System.Net.Dns.GetHostByAddress(my_net & i.ToString).HostName
                    Catch ex As Exception
                        host_name(i) = my_net & i.ToString
                    End Try
                Else
                    test(i) = False
                    host_name(i) = my_net & i.ToString
                End If
            Next
            bg3_completed = True
        End Sub
    
        Private Sub BackgroundWorker4_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker4.DoWork
            For i As Integer = 4 To 252 Step 4
                If My.Computer.Network.Ping(my_net & i.ToString, ping_timeout_ms) Then
                    test(i) = True
                    Try
                        host_name(i) = System.Net.Dns.GetHostByAddress(my_net & i.ToString).HostName
                    Catch ex As Exception
                        host_name(i) = my_net & i.ToString
                    End Try
                Else
                    test(i) = False
                    host_name(i) = my_net & i.ToString
                End If
            Next
            bg4_completed = True
        End Sub
    
        Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
            ComboBox1.Items.Clear()
            ComboBox2.Items.Clear()
            For i As Integer = 1 To 254
                If test(i) Then
                    ComboBox1.Items.Add(host_name(i))
                Else
                    ComboBox2.Items.Add(host_name(i))
                End If
            Next
            MsgBox("Lista caricata!")
        End Sub
    End Class
    
  • Re: Nslookup per determinare hostname

    Si scusa...
  • Re: Nslookup per determinare hostname

    Continuando con il mio progetto sto creando un nuovo form all'interno del quale ho inserito tutti gli hostname presenti nella mia rete
    quindi selezionandone uno vorrei vedere più informazioni possibili (macaddress - sist.op - ram - disco - etc etc)

    sono partito dal l'IP e quindi dal mac address:
    'ricavo IP - FUNZIONA
    Dim ipaddress As String = CType(Dns.GetHostByName(tempScanHostName).AddressList.GetValue(0), IPAddress).ToString
    lblIP.Visible = True : lblIP.Text = "Indirizzo IP: " & ipaddress.ToString

    'ricavo MacAddress
    Dim theNetworkInterfaces() As System.Net.NetworkInformation.NetworkInterface = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
    For Each currentInterface As System.Net.NetworkInformation.NetworkInterface In theNetworkInterfaces

    If currentInterface.OperationalStatus = Net.NetworkInformation.OperationalStatus.Up And currentInterface.NetworkInterfaceType.ToString() = "Ethernet" Then
    Try
    Dim theManagementScope As New ManagementScope("\\" & tempScanHostName & "\root\cimv2")
    Dim theQueryString As String = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 1"
    Dim theObjectQuery As New ObjectQuery(theQueryString)
    Dim theSearcher As New ManagementObjectSearcher(theManagementScope, theObjectQuery)
    Dim theResultsCollection As ManagementObjectCollection = theSearcher.Get()

    For Each currentResult As ManagementObject In theResultsCollection
    lblMac.Visible = True : lblMac.Text = "Mac Address (" & currentResult("MacAddress").ToString() & " Card)"
    'MessageBox.Show(currentResult("MacAddress").ToString())
    Next
    nic = "Mac Address (" & currentInterface.NetworkInterfaceType.ToString & " Card)"
    lblMac.Visible = True : lblMac.Text = "Mac Address (" & currentInterface.NetworkInterfaceType.ToString & " Card)"

    Catch ex As Exception
    MsgBox("Catch ex As Exception")
    End Try
    MsgBox("End Try")
    End If
    Next
    purtroppo quando eseguo le istruzione relativa al mac address il programma ritorna sul form chiamante e non fa nulla
    da debug non vedo progressi in nessun form....

    dove sbaglio? grazie
  • Re: Nslookup per determinare hostname

    Il codice mettilo dentro i tag CODE (pulsante < / > ) altrimenti non è leggibile

    Usa i moduli
    
    Imports System.Net.NetworkInformation
    
    Module Module1
        Friend NetworkInterfaces() As NetworkInterface
        Friend MACAddress As String = "00:00:00:00:00:00"
    
        Friend Sub Network_Probe()
            Try
                NetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces()
                For Each ni In NetworkInterfaces
                    If ni.OperationalStatus = OperationalStatus.Up AndAlso ni.NetworkInterfaceType = NetworkInterfaceType.Ethernet Then
                        Dim MAC() As Byte = ni.GetPhysicalAddress().GetAddressBytes
                        If Not MAC Is Nothing AndAlso MAC.Length >= 6 Then
                            MACAddress = Hex(MAC(0)).PadLeft(2, "0") & ":" & Hex(MAC(1)).PadLeft(2, "0") & ":" & Hex(MAC(2)).PadLeft(2, "0") & ":" _
                                         & Hex(MAC(3)).PadLeft(2, "0") & ":" & Hex(MAC(4)).PadLeft(2, "0") & ":" & Hex(MAC(5)).PadLeft(2, "0")
                            Exit For
                        End If
                    End If
                Next
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub
    End Module
    
    
    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Network_Probe()
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            MsgBox("MAC = " & MACAddress)
        End Sub
    End Class
    
  • Re: Nslookup per determinare hostname

    Grazie!
    ma io vorrei ottenere il mac address di un client della mia lan, passando il nomehost....
  • Re: Nslookup per determinare hostname

    Questo da IP
    
    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Network_Probe()
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            MsgBox("MAC Host = " & MACHost & vbCrLf & "MAC Address = " & MACAddress)
        End Sub
    End Class
    
    
    Imports System.Net.NetworkInformation
    Imports System.Diagnostics
    
    Module Module1
        Friend NetworkInterfaces() As NetworkInterface
        Friend MACHost As String = "00:00:00:00:00:00"
    
        Friend TestIP As String = "192.168.0.1"
        Friend MACAddress As String = "00:00:00:00:00:00"
    
        Friend Sub Network_Probe()
            Try
                NetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces()
                For Each ni In NetworkInterfaces
                    If ni.OperationalStatus = OperationalStatus.Up AndAlso ni.NetworkInterfaceType = NetworkInterfaceType.Ethernet Then
                        Dim MAC() As Byte = ni.GetPhysicalAddress().GetAddressBytes
                        If Not MAC Is Nothing AndAlso MAC.Length >= 6 Then
                            MACHost = Hex(MAC(0)).PadLeft(2, "0") & ":" & Hex(MAC(1)).PadLeft(2, "0") & ":" & Hex(MAC(2)).PadLeft(2, "0") & ":" _
                                         & Hex(MAC(3)).PadLeft(2, "0") & ":" & Hex(MAC(4)).PadLeft(2, "0") & ":" & Hex(MAC(5)).PadLeft(2, "0")
                            Exit For
                        End If
                    End If
                Next
    
                Dim ping As Ping = New Ping()
                AddHandler ping.PingCompleted, AddressOf Ping_completed
                ping.SendAsync(TestIP, 500, TestIP)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub
    
        Private Sub Ping_completed(ByVal sender As Object, ByVal e As PingCompletedEventArgs)
            If e.Reply IsNot Nothing AndAlso e.Reply.Status = IPStatus.Success AndAlso CStr(e.UserState) = TestIP Then
                Dim proc As Process = New Process()
                proc.StartInfo.FileName = "arp"
                proc.StartInfo.Arguments = "-a " & TestIP
                proc.StartInfo.UseShellExecute = False
                proc.StartInfo.RedirectStandardOutput = True
                proc.StartInfo.CreateNoWindow = True
                proc.Start()
                Dim s As String() = proc.StandardOutput.ReadToEnd().Split("-")
                If Not s Is Nothing AndAlso s.Length >= 8 Then
                    MACAddress = s(3).Substring(Math.Max(0, s(3).Length - 2)).ToUpper & ":" & s(4).ToUpper & ":" & s(5).ToUpper _
                        & ":" & s(6).ToUpper & ":" & s(7).ToUpper & ":" + s(8).Substring(0, 2).ToUpper
                End If
            Else
                MsgBox("No reply from IP " & TestIP)
            End If
        End Sub
    End Module
    
    Dal nome host lo ricavi dagli esempi precedenti
Devi accedere o registrarti per scrivere nel forum
21 risposte