Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than kernel32, prefix the name with the module name and a period.
NetBIOS (kernel32)
.
C# Signature:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct _NCB
{
public Commands ncb_command; /* command code */
public byte ncb_retcode; /* return code */
public byte ncb_lsn; /* local session number */
public byte ncb_num; /* number of our network name */
//[MarshalAs(UnmanagedType.ByValArray, SizeConst = NCBNAMSZ)]
//[MarshalAs(UnmanagedType.LPStr)]
//[MarshalAs(UnmanagedType.LPArray)]
public IntPtr ncb_buffer; /* address of message buffer */
public ushort ncb_length; /* size of message buffer */
[MarshalAs(UnmanagedType.ByValArray, SizeConst = NativeMethods.NCBNAMSZ)]
public byte[] ncb_callname; /* blank-padded name of remote */
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NativeMethods.NCBNAMSZ)]
public byte[] ncb_name; /* our blank-padded netname */
public byte ncb_rto; /* rcv timeout/retry count */
public byte ncb_sto; /* send timeout/sys timeout */
public IntPtr postroutine;//void (CALLBACK *ncb_post)( struct _NCB * ); /* POST routine address */
public byte ncb_lana_num; /* lana (adapter) number */
public byte ncb_cmd_cplt; /* 0xff => commmand pending */
[MarshalAs(UnmanagedType.LPArray, SizeConst=10)]
public byte[/*10*/] ncb_reserve; /* reserved, used by BIOS */
public IntPtr ncb_event; /* HANDLE to Win32 event which */
/* will be set to the signalled */
/* state when an ASYNCH command */
/* completes */
}
Private Declare Function Netbios Lib "netapi32.dll" ( _
ByRef pncb As NCB _
) As Byte
User-Defined Types:
Private Const NCBNAMSZ As Integer = 16
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Private Structure NCB
Dim ncb_command As Byte
Dim ncb_retcode As Byte
Dim ncb_lsn As Byte
Dim ncb_num As Byte
Dim ncb_buffer As IntPtr
Dim ncb_length As Short
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=NCBNAMSZ)> Dim ncb_callname As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=NCBNAMSZ)> Dim ncb_name As String
Dim ncb_rto As Byte
Dim ncb_sto As Byte
Dim ncb_post As IntPtr
Dim ncb_lana_num As Byte
Dim ncb_cmd_cplt As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=10)> Dim ncb_reserve() As Byte
Dim ncb_event As IntPtr
End Structure
Private Const NCBNAMSZ As Integer = 16
Private Const MAX_LANA As Integer = 254
Private Const NCBRESET As Integer = &H32
Private Const NCBASTAT As Integer = &H33
Private Const NCBENUM As Integer = &H37
<StructLayout(LayoutKind.Sequential)> _
Private Structure ASTAT
Dim adapt As ADAPTER_STATUS
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=30)> Dim NameBuff() As NAME_BUFFER
End Structure
' Get the MAC Address of a remote PC
Function GetMACAddress(ByVal RemoteIP As String) As String
Dim sb As New StringBuilder
Dim myNcb As New NCB
Dim myAdapt As New ADAPTER_STATUS
Dim myASTAT As New ASTAT
Dim myLana As New LANA_ENUM
Dim ptr As IntPtr
Dim i As Integer
Dim bRet, FirstLANA As Byte
' First, we'll need to discover which LANA number is being used.
' So, we create a LANA_ENUM buffer (with a bit of pointer magic)
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(myLana))
Marshal.StructureToPtr(myLana, ptr, False)
' execute the NetBIOS command
bRet = Netbios(myNcb)
If bRet <> 0 Then
Marshal.FreeHGlobal(ptr)
Throw New ApplicationException("Can't get the list of LANAs, error code=" & bRet)
Return Nothing
End If
' cast it back with pointer magic
myLana = CType(Marshal.PtrToStructure(ptr, GetType(LANA_ENUM)), LANA_ENUM)
FirstLANA = myLana.lana(0)
' Next we do a "reset" on the NetBIOS interface
myNcb.ncb_command = NCBRESET
myNcb.ncb_lana_num = FirstLANA
' execute the NetBIOS command
bRet = Netbios(myNcb)
If bRet <> 0 Then
Marshal.FreeHGlobal(ptr)
Throw New ApplicationException("Can't Reset the NetBIOS interface, error code=" & bRet)
Return Nothing
End If
' Create an Adapater Status packet (with more pointer magic)
Marshal.FreeHGlobal(ptr)
myASTAT.adapt = myAdapt
ptr = Marshal.AllocHGlobal(Marshal.SizeOf(myASTAT))
Marshal.StructureToPtr(myASTAT, ptr, False)
' Now we load up our adapter request
myNcb.ncb_command = NCBASTAT
myNcb.ncb_lana_num = FirstLANA
myNcb.ncb_callname = RemoteIP.PadRight(NCBNAMSZ, " "c)
myNcb.ncb_buffer = ptr
myNcb.ncb_length = CShort(Marshal.SizeOf(myASTAT))
' execute the NetBIOS command
bRet = Netbios(myNcb)
If bRet <> 0 Then
Marshal.FreeHGlobal(ptr)
Throw New ApplicationException("Can't get the Adapter Status, error code=" & bRet)
Return Nothing
End If
' cast it back with pointer magic
myASTAT = CType(Marshal.PtrToStructure(ptr, GetType(ASTAT)), ASTAT)
' make a string version of the MAC address
For i = 0 To 5
sb.AppendFormat("{0:X2}:", myASTAT.adapt.adapter_address(i))
Next
Marshal.FreeHGlobal(ptr)
Return sb.ToString.TrimEnd(":"c)
End Function
Alternative Managed API:
For Windows 7 64 bit - make sure to compile platform as x86. Also, had to marshal each item in NCB structure to get it work:
Do you know one? Please contribute it!
'-----------------------------------------------------------
' NetBIOS Network Control Block structure--which is used to
' issue all commands to the NetBIOS protocol
'-----------------------------------------------------------
Public Enum netbstrcs
netNameLen = 16 '[Length if name in bytes]
netresvLen = 11 '[Length of reserve array]
netbuffer = 32000 '[Total size of data butter]
netnumSess = 10 '[Total number of active sessions]
netMAC = 7 '[MAC address len]
netnumNames = 17 '[Number of netbios names in adapter table]
End Enum
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Structure NCB
<MarshalAs(UnmanagedType.U1)> _
Public ncbCommand As Byte
<MarshalAs(UnmanagedType.U1)> _
Public ncbRetcode As Byte
<MarshalAs(UnmanagedType.U1)> _
Public ncbLSN As Byte
<MarshalAs(UnmanagedType.U1)> _
Public ncbNum As Byte
<MarshalAs(UnmanagedType.SysUInt)> _
Public ncbBuffer As IntPtr
<MarshalAs(UnmanagedType.U2)> _
Public ncbLength As Int16
<MarshalAs(UnmanagedType.ByValArray, ArraySubType:=UnmanagedType.U1, _
SizeConst:=netbstrcs.netNameLen)> Dim ncbCallname() As Byte
<MarshalAs(UnmanagedType.ByValArray, ArraySubType:=UnmanagedType.U1, _
SizeConst:=netbstrcs.netNameLen)> Dim ncbName() As Byte
<MarshalAs(UnmanagedType.U1)> _
Public ncbRTO As Byte
<MarshalAs(UnmanagedType.U1)> _
Public ncbSTO As Byte
<MarshalAs(UnmanagedType.U4)> _
Public ncbPost As UInt32 'IntPtr
<MarshalAs(UnmanagedType.U1)> _
Public ncbLANAnum As Byte
<MarshalAs(UnmanagedType.U1)> _
Public ncbCmdCplt As Byte
<MarshalAs(UnmanagedType.ByValArray, ArraySubType:=UnmanagedType.U1, _
SizeConst:=netbstrcs.netresvLen)> Dim ncbReserve() As Byte
<MarshalAs(UnmanagedType.U4)> _
Public ncbEvent As Int32 'IntPtr
End Structure
The Netbios function interprets and executes the specified network control block (NCB). The Netbios function is provided primarily for applications that were written for the NetBIOS interface and need to be ported to Windows. Applications not requiring compatibility with NetBIOS should use other interfaces, such as mailslots, named pipes, RPC, or distributed COM to accomplish tasks similar to those supported by NetBIOS. These other interfaces are more flexible and portable.
5/23/2014 9:41:50 AM - jonr@reedholm.com-71.114.254.154
The Netbios function interprets and executes the specified network control block (NCB). The Netbios function is provided primarily for applications that were written for the NetBIOS interface and need to be ported to Windows. Applications not requiring compatibility with NetBIOS should use other interfaces, such as mailslots, named pipes, RPC, or distributed COM to accomplish tasks similar to those supported by NetBIOS. These other interfaces are more flexible and portable.
5/23/2014 9:41:50 AM - jonr@reedholm.com-71.114.254.154
The Netbios function interprets and executes the specified network control block (NCB). The Netbios function is provided primarily for applications that were written for the NetBIOS interface and need to be ported to Windows. Applications not requiring compatibility with NetBIOS should use other interfaces, such as mailslots, named pipes, RPC, or distributed COM to accomplish tasks similar to those supported by NetBIOS. These other interfaces are more flexible and portable.
5/23/2014 9:41:50 AM - jonr@reedholm.com-71.114.254.154
The NCB structure represents a network control block. It contains information about the command to perform, an optional post routine, an optional event handle, and a pointer to a buffer that is used for messages or other data. A pointer to this structure is passed to the (NetBIOS) function
11/4/2011 5:51:23 AM - -84.134.175.235
Used by the (NetBIOS) function to retrieve the list of LAN Adapters. The LANA_ENUM structure is pointed to by the ncb_buffer member of the NCB structure when an application issues the NCBENUM command.
11/2/2020 2:07:30 PM - -192.180.154.40
The ADAPTER_STATUS structure contains information about a network adapter via the (NetBIOS) API call. This structure is pointed to by the ncb_buffer member of the NCB structure. ADAPTER_STATUS is followed by as many NAME_BUFFER structures as required to describe the network adapters on the system
10/25/2014 8:43:27 AM - egray1@hot.rr.com-150.113.7.99
The NAME_BUFFER structure contains information about a local network name via the (NetBIOS) API Call. One or more NAME_BUFFER structures follows an ADAPTER_STATUS structure when an application specifies the NCBASTAT command in the ncb_command member of the NCB structure.
4/24/2007 8:51:17 AM - anonymous
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).