我有这个问题。
有可能吗?我的Android手机上有一个应用程序可以列出所有连接的ips并获取有关它们的信息,例如:设备名称,mac-adress。
非常感谢帮助。谢谢!
答案 0 :(得分:0)
我发现this code几周前浏览我的网络,对我来说效果很好。这是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
答案 1 :(得分:0)
简而言之,我在几年前写过并且效果很好。代码可能需要一些“高级”更新,因为我把它写成vb.net的新手,但正如我所说,它工作得很好。它被用于执法定制的pc,所以......
100%VB.Net
回答你的评论,正如我所说的,我在几年前写的,它可以使用一些更新,我敢肯定。论坛中概述了该用途,但我将重申更多细节。
zip文件包含整个项目。这意味着您可以将其简单地提取到VS项目文件夹中,然后将其打开以查看其使用示例。正如我所看到的,库本身是基于F5调试构建的,因此它已经存在于目录Driver Detective\bin\Debug
中,您可以运行该程序并从bin\Release
获取相同的文件。
您需要的文件是Drive Detective.dll
。我不记得(已经有一段时间了)整个过程,但是将该文件移动到您可以轻松找到的位置,或者只记录它在Debug
目录中的位置。打开您要使用的项目,将其添加到您的库列表中。就像我说的,自从我使用VS以来已经很长时间了,所以我不记得调用了什么进程,但基本上,将lib添加到你的项目中,这样就可以使用它了:
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
前面介绍了如何查找CDRom类型的所有连接驱动器。这只是众多用途中的一种。它只包含一些公共函数,可直接满足处理驱动器检测的“需求”。它的优势在于它的事件。一旦添加并创建了处理程序(meClass = New driverDetective(Me.Handle)
),就会发现您突然有一个完整的事件驱动类来处理驱动器检测。
Long
字节值转换为Compact表格,如1024Bytes = 1kB 能够在工作中挖掘VS并运行一次并检查,如您所见,它确实可用于检测网络驱动器。