Vb.net 是否可以扫描网络中已连接的设备并在程序中列出它们?

Vb.net 是否可以扫描网络中已连接的设备并在程序中列出它们?,vb.net,Vb.net,我有这个问题要问你 可能吗?我的android手机上有一个应用程序,可以列出所有连接的IP,并获取有关它们的信息,如:设备名称、mac地址 非常感谢您的帮助。谢谢大家! 几周前,为了浏览我的网络,我发现它对我来说非常有效。以下是VB转换: Imports System.Runtime.InteropServices Imports System.Security Imports System.Collections Imports System.Windows.Forms Namespace

我有这个问题要问你

可能吗?我的android手机上有一个应用程序,可以列出所有连接的IP,并获取有关它们的信息,如:设备名称、mac地址

非常感谢您的帮助。谢谢大家!

几周前,为了浏览我的网络,我发现它对我来说非常有效。以下是VB转换:

Imports System.Runtime.InteropServices
Imports System.Security
Imports System.Collections
Imports System.Windows.Forms

Namespace ListNetworkComputers
    #Region "NetworkBrowser CLASS"
    ''' <summary>
    ''' Provides a mechanism for supplying
    ' a list of all PC names in the local network.
    ''' This collection of PC names is used in the form 
    ''' 


''' This class makes use of a DllImport instruction.
''' The purpose of which is as follows:
''' When a DllImport declaration is made
''' in managed code (C#) it is a call to a legacy
''' unmanaged code module, normally
''' a C++ Dynamic Link Library. These C++ Dll's are
''' usually part of the operating system API,
''' or some other vendors API, and must be 
''' used to carry out operations that are not
''' native within the managed code C# framework. 
''' This is fairly normal within the windows world.
''' The only thing that needs careful consideration
''' is the construction of the correct type of STRUCTS,
''' object pointers, and attribute markers,
''' which all contribute to making the link
''' between managed (C#) and unmanaged code (C++)
''' more seamless
''' 

''' This class makes use of the following Dll calls
''' <list type="bullet">
''' <item>
''' <description> Netapi32.dll : NetServerEnum,
''' The NetServerEnum function lists all servers
''' of the specified type that are visible in
''' a domain. For example, an application can call 
''' NetServerEnum to list all domain controllers
''' only or all SQL servers only.
''' You can combine bit masks to list several
''' types. For example, a value of 0x00000003 
''' combines the bit masks for SV_TYPE_WORKSTATION
''' (0x00000001) and SV_TYPE_SERVER (0x00000002).
''' </description>
''' </item>
''' <item>
''' <description> Netapi32.dll : NetApiBufferFree,
''' The NetApiBufferFree function frees 
''' the memory that the NetApiBufferAllocate
''' function allocates. Call NetApiBufferFree 
''' to free the memory that other network
''' management functions return.</description>
''' </item>
''' </list>
''' </summary>
Public NotInheritable Class NetworkBrowser
    #Region "Dll Imports"

    'declare the Netapi32 : NetServerEnum method import

    ''' <summary>
    ''' Netapi32.dll : The NetServerEnum function lists all servers
    ''' of the specified type that are
    ''' visible in a domain. For example, an 
    ''' application can call NetServerEnum
    ''' to list all domain controllers only
    ''' or all SQL servers only.
    ''' You can combine bit masks to list
    ''' several types. For example, a value 
    ''' of 0x00000003  combines the bit
    ''' masks for SV_TYPE_WORKSTATION 
    ''' (0x00000001) and SV_TYPE_SERVER (0x00000002)
    ''' </summary>
    ' must be null
    ' null for login domain
    <DllImport("Netapi32", CharSet := CharSet.Auto, SetLastError := True), SuppressUnmanagedCodeSecurityAttribute> _
    Public Shared Function NetServerEnum(ServerNane As String, dwLevel As Integer, ByRef pBuf As IntPtr, dwPrefMaxLen As Integer, ByRef dwEntriesRead As Integer, ByRef dwTotalEntries As Integer, _
        dwServerType As Integer, domain As String, ByRef dwResumeHandle As Integer) As Integer
    End Function

    'declare the Netapi32 : NetApiBufferFree method import

    ''' <summary>
    ''' Netapi32.dll : The NetApiBufferFree function frees 
    ''' the memory that the NetApiBufferAllocate function allocates. 
    ''' Call NetApiBufferFree to free
    ''' the memory that other network 
    ''' management functions return.
    ''' </summary>
    <DllImport("Netapi32", SetLastError := True), SuppressUnmanagedCodeSecurityAttribute> _
    Public Shared Function NetApiBufferFree(pBuf As IntPtr) As Integer
    End Function

    'create a _SERVER_INFO_100 STRUCTURE
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure _SERVER_INFO_100
        Friend sv100_platform_id As Integer
        <MarshalAs(UnmanagedType.LPWStr)> _
        Friend sv100_name As String
    End Structure
    #End Region
    #Region "Public Constructor"
    ''' <SUMMARY>
    ''' Constructor, simply creates a new NetworkBrowser object
    ''' </SUMMARY>

    Public Sub New()
    End Sub
    #End Region
    #Region "Public Methods"
    ''' <summary>
    ''' Uses the DllImport : NetServerEnum
    ''' with all its required parameters
    ''' (see http://msdn.microsoft.com/library/default.asp?
    '''      url=/library/en-us/netmgmt/netmgmt/netserverenum.asp
    ''' for full details or method signature) to
    ''' retrieve a list of domain SV_TYPE_WORKSTATION
    ''' and SV_TYPE_SERVER PC's
    ''' </summary>
    ''' <returns>Arraylist that represents
    ''' all the SV_TYPE_WORKSTATION and SV_TYPE_SERVER
    ''' PC's in the Domain</returns>
    Public Function getNetworkComputers() As ArrayList
        'local fields
        Dim networkComputers As New ArrayList()
        Const  MAX_PREFERRED_LENGTH As Integer = -1
        Dim SV_TYPE_WORKSTATION As Integer = 1
        Dim SV_TYPE_SERVER As Integer = 2
        Dim buffer As IntPtr = IntPtr.Zero
        Dim tmpBuffer As IntPtr = IntPtr.Zero
        Dim entriesRead As Integer = 0
        Dim totalEntries As Integer = 0
        Dim resHandle As Integer = 0
        Dim sizeofINFO As Integer = Marshal.SizeOf(GetType(_SERVER_INFO_100))


        Try
            'call the DllImport : NetServerEnum 
            'with all its required parameters
            'see http://msdn.microsoft.com/library/
            'default.asp?url=/library/en-us/netmgmt/netmgmt/netserverenum.asp
            'for full details of method signature
            Dim ret As Integer = NetServerEnum(Nothing, 100, buffer, MAX_PREFERRED_LENGTH, entriesRead, totalEntries, _
                SV_TYPE_WORKSTATION Or SV_TYPE_SERVER, Nothing, resHandle)
            'if the returned with a NERR_Success 
            '(C++ term), =0 for C#
            If ret = 0 Then
                'loop through all SV_TYPE_WORKSTATION 
                'and SV_TYPE_SERVER PC's
                For i As Integer = 0 To totalEntries - 1
                    'get pointer to, Pointer to the 
                    'buffer that received the data from
                    'the call to NetServerEnum. 
                    'Must ensure to use correct size of 
                    'STRUCTURE to ensure correct 
                    'location in memory is pointed to
                    tmpBuffer = New IntPtr(CInt(buffer) + (i * sizeofINFO))
                    'Have now got a pointer to the list 
                    'of SV_TYPE_WORKSTATION and 
                    'SV_TYPE_SERVER PC's, which is unmanaged memory
                    'Needs to Marshal data from an 
                    'unmanaged block of memory to a 
                    'managed object, again using 
                    'STRUCTURE to ensure the correct data
                    'is marshalled 
                    Dim svrInfo As _SERVER_INFO_100 = CType(Marshal.PtrToStructure(tmpBuffer, GetType(_SERVER_INFO_100)), _SERVER_INFO_100)

                    'add the PC names to the ArrayList
                    networkComputers.Add(svrInfo.sv100_name)
                Next
            End If
        Catch ex As Exception
            MessageBox.Show("Problem with acessing " + "network computers in NetworkBrowser " + vbCr & vbLf & vbCr & vbLf & vbCr & vbLf + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
            Return Nothing
        Finally
            'The NetApiBufferFree function frees 
            'the memory that the 
            'NetApiBufferAllocate function allocates
            NetApiBufferFree(buffer)
        End Try
        'return entries found
        Return networkComputers

    End Function
    #End Region
End Class
#End Region
End Namespace
导入System.Runtime.InteropServices
导入系统。安全
导入系统集合
导入System.Windows.Forms
名称空间列表网络计算机
#区域“网络浏览器类”
''' 
''提供了一种提供
'本地网络中所有PC名称的列表。
''此PC名称集合在表单中使用
''' 
''此类使用DllImport指令。
“其目的如下:
''当做出DllImport声明时
在托管代码(C#)中,它是对遗留代码的调用
''非托管代码模块,通常
''C++动态链接库。这些C++的DLL是
''通常是操作系统API的一部分,
''或其他供应商的API,并且必须
''用于执行不属于
“托管代码C#框架中的本机”。
''这在windows世界中是相当正常的。
''唯一需要仔细考虑的事情
''是正确类型结构的构造,
''对象指针和属性标记,
''这些都有助于建立链接
托管代码(C#)和非托管代码(C++)之间的''''
“更无缝”
''' 
''此类使用以下Dll调用
''' 
''' 
''Netapi32.dll:NetServerEnum,
''NetServerEnum函数列出所有服务器
在中可见的指定类型的“”
''一个域名。例如,应用程序可以调用
''NetServerEnum以列出所有域控制器
''仅限SQL Server或所有SQL Server。
''您可以组合位掩码来列出几个
''类型。例如,值0x00000003
''结合了SV_类型_工作站的位掩码
''(0x00000001)和SV_类型_服务器(0x00000002)。
''' 
''' 
''' 
''Netapi32.dll:NetApiBufferFree,
''NetApiBufferFree函数释放
''NetapiBuffer分配的内存
''函数分配。调用NetApiBufferFree
''以释放其他网络的内存
''管理功能返回。
''' 
''' 
''' 
公共不可继承类网络浏览器
#区域“Dll导入”
'声明Netapi32:NetServerEnum方法导入
''' 
''Netapi32.dll:NetServerEnum函数列出所有服务器
指定类型的“”是
“在域中可见”。例如,一个
''应用程序可以调用NetServerEnum
''仅列出所有域控制器
''或仅限所有SQL Server。
''您可以将位掩码组合到列表中
''有几种类型。例如,一个值
0x00000003的“”组合了该位
SV_类型_工作站的“屏蔽”
''(0x00000001)和SV_类型_服务器(0x00000002)
''' 
'必须为空
'登录域为空
_
公共共享函数NetServerEnum(ServerNane作为字符串,dwLevel作为整数,ByRef pBuf作为IntPtr,dwPrefMaxLen作为整数,ByRef dwEntriesRead作为整数,ByRef dwTotalEntries作为整数_
dwServerType为整数,域为字符串,ByRef dwResumeHandle为整数)为整数
端函数
'声明Netapi32:NetApiBufferFree方法导入
''' 
''Netapi32.dll:NetApiBufferFree函数释放
''NetApiBufferAllocate函数分配的内存。
''调用NetApiBufferFree以释放
''另一个网络的内存
''管理功能返回。
''' 
_
公共共享函数NetApiBufferFree(pBuf作为IntPtr)作为整数
端函数
'创建一个_服务器_信息_100结构
_
公共结构\u服务器\u信息\u 100
Friend sv100_平台_id为整数
_
Friend sv100_名称作为字符串
端部结构
#末端区域
#地区“公共建设者”
''' 
''构造函数,只创建一个新的NetworkBrowser对象
''' 
公共分新()
端接头
#末端区域
#区域“公共方法”
''' 
''使用DllImport:netserver枚举
''及其所有必需参数
''(见http://msdn.microsoft.com/library/default.asp?
''url=/library/en-us/netmgmt/netmgmt/netserverenum.asp
''用于完整细节或方法签名)至
''检索域SV_类型_工作站的列表
''和SV_类型_服务器PC
''' 
''表示
''所有SV_类型_工作站和SV_类型_服务器
''PC在域中
公共函数getNetworkComputers()作为ArrayList
“本地字段
Dim networkComputers作为新的ArrayList()
Const MAX_PREFERRED_长度为整数=-1
尺寸SV_类型_工作站为整数=1
Dim SV_类型_服务器为整数=2
Dim缓冲区为IntPtr=IntPtr.Zero
尺寸tmpBuffer为IntPtr=IntPtr.Zero
Dim entriesRead为整数=0
Dim totalEntries为整数=0
Dim resHandle作为整数=0
Dim sizeofINFO As Integer=Marshal.SizeOf(GetType(\u SERVER\u INFO\u 100))
尝试
'调用DllImport:netserver枚举
'及其所有必需参数
”“看到了吗http://msdn.microsoft.com/library/
'default.asp?url=/library/en-us/netmgmt/netmgmt/netserverenum.asp
'获取方法签名的完整详细信息
Dim ret As Integer=NetServerEnum(无、100、缓冲区、最大首选长度、entriesRead、totalEntries、_
SV_类型_工作站或SV_类型_服务器,无,重新处理)
“如果他回来的时候成绩不好
'(C++术语),=0表示C#
如果ret=0,则
'循环通过所有SV_类型_工作站
'和SV_类型_服务器PC's
对于i作为整数=0到totalEntries-1
Imports driver Detective.driver Detective
Private Sub myForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load '<- this obviously a window load event
    meClass = New driverDetective(Me.Handle)
    Dim test As Dictionary(Of String, Dictionary(Of String, Object)) = meClass.findDrives(DriveType.CDRom) 'this will find any and all connected CDRom's