Click here to Skip to main content
15,910,277 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
We have around 400 PC's in our network which is segregated by department wise. Each department has its own subnet for example : dept1 has the ip series 192.168.20.X and dept2 has 192.168.11.X.

My question is that how could i get the ipaddress, hostname and mac address with a VB .net application and store it in the database.

Hope i am clear enough.

Thank you.

What I have tried:

I have tried using:

VB
<pre>For i = 1 To 254
            Try
                hostname = ""
                ipaddr = "192.168.12." & i.ToString
                hostname = (System.Net.Dns.GetHostEntry("192.168.12." & i.ToString).HostName.ToString)
                timestamp = DateAndTime.Now.ToString
                If hostname <> "" Then
                    If con.State = ConnectionState.Closed Then
                        con.Open()
                    End If
                    sql = "insert into ipstats values(?,?,?)"
                    cmd = New SqlCeCommand(sql, con)
                    cmd.Parameters.AddWithValue("hostname", hostname)
                    cmd.Parameters.AddWithValue("ipddr", ipaddr)
                    cmd.Parameters.AddWithValue("timestamp", timestamp)
                    retvals = cmd.ExecuteNonQuery()
                End If
            Catch ex As Exception
            End Try
        Next

But it take around an hour to scan whole network and it does not get all the machine in the network.

And also i could not figure out how to get mac address.
Posted
Updated 26-Aug-17 22:10pm

1 solution

A quick Google Search using: c# local network discovery - Google Search[^]

Found this: C# - SubnetScanner - Scan your (local) Network - YouTube[^] which has a support page & source download link: C# Subnet Scanner - KIJUKA[^]

I know that this is C#, but should not be too difficult to convert to VB. Upload the zipped project file to here: Code Converter[^] and it will do most of the work for you...

UPDATE: Actually, this is what you are looking for courtesy of OriginalGriff[^] : Retrieving IP and MAC addresses for a LAN[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900