public uint Smb2QueryNetworkInterfaceInfo(out NETWORK_INTERFACE_INFO_Response[] networkInterfaceInfos) { byte[] responseInput; byte[] responseOutput; Packet_Header packetHeader; IOCTL_Response ioCtlResponse; // IoCtl Query Network Interface INFO this.IoCtl( 1, 64, Packet_Header_Flags_Values.FLAGS_SIGNED, messageId, sessionId, TreeId, CtlCode_Values.FSCTL_QUERY_NETWORK_INTERFACE_INFO, new FILEID { Persistent = 0xffffffffffffffff, Volatile = 0xffffffffffffffff }, 0, new byte[0], 65536, IOCTL_Request_Flags_Values.SMB2_0_IOCTL_IS_FSCTL, out responseInput, out responseOutput, out packetHeader, out ioCtlResponse); CalculateSmb2AvailableCredits(1, packetHeader.CreditRequestResponse); if ((NtStatus)packetHeader.Status != NtStatus.STATUS_SUCCESS) { networkInterfaceInfos = null; return(packetHeader.Status); } // parse network interface information networkInterfaceInfos = Smb2Utility.UnmarshalNetworkInterfaceInfoResponse(responseOutput); return(0); }
private bool GetRemoteNetworkInterfaceInformation(IPAddress ip) { try { using (var client = new SMBDClient(DetectionInfo.ConnectionTimeout)) { client.Connect(ip, IPAddress.Parse(DetectionInfo.DriverNonRdmaNICIPAddress)); client.Smb2Negotiate(new DialectRevision[] { DialectRevision.Smb30, DialectRevision.Smb302, DialectRevision.Smb311 }); client.Smb2SessionSetup(DetectionInfo.Authentication, DetectionInfo.DomainName, DetectionInfo.SUTName, DetectionInfo.UserName, DetectionInfo.Password); uint treeId; string ipcPath = Smb2Utility.GetIPCPath(DetectionInfo.SUTName); client.Smb2TreeConnect(ipcPath, out treeId); byte[] input; byte[] output; client.IoCtl(treeId, CtlCode_Values.FSCTL_QUERY_NETWORK_INTERFACE_INFO, FILEID.Invalid, IOCTL_Request_Flags_Values.SMB2_0_IOCTL_IS_FSCTL, out input, out output); var networkInterfaces = Smb2Utility.UnmarshalNetworkInterfaceInfoResponse(output); var remoteInterfaces = ParseRemoteNetworkInterfaceInformation(networkInterfaces); FilterNetworkInterfaces(remoteInterfaces); return(true); } } catch (Exception ex) { DetectorUtil.WriteLog(String.Format("GetRemoteNetworkInterfaceInformation failed for {0}: {1}.", ip.ToString(), ex.ToString())); return(false); } }