SharpCifs.Std
SharpCifs.Std copied to clipboard
"Connect & Auth:" examples return true for the base domain of any local IP
Code (Mostly from http://sharpcifsstd.dobes.jp/ with a slight modification)
SharpCifs.Config.SetProperty("jcifs.smb.client.lport", "8137");
string invalidIP = "192.168.0.240"; // Make sure there are no machines on your local network with the specific IP
//string to Auth-Object.
Console.WriteLine("SMB1");
var auth1 = new NtlmPasswordAuthentication("anonymous:Password");
var smb1 = new SmbFile($"smb://{invalidIP}/ ", auth1);
Console.WriteLine($"exists? {smb1.Exists()}");
//3 string to Auth-Object.
Console.WriteLine("SMB2");
var auth2 = new NtlmPasswordAuthentication(null, "anonymous", "Password");
var smb2 = new SmbFile($"smb://{invalidIP}/", auth2);
Console.WriteLine($"exists? {smb2.Exists()}");
//Insert auth info into URL.
Console.WriteLine("SMB3");
var smb3 = new SmbFile($"smb://Username:Password@{invalidIP}/");
Console.WriteLine($"exists? {smb3.Exists()}");
//You can store authentication information in SharpCifs.Std.
SharpCifs.Config.SetProperty("jcifs.smb.client.username", "UserName");
SharpCifs.Config.SetProperty("jcifs.smb.client.password", "Password");
Console.WriteLine("SMB4");
var smb4 = new SmbFile($"smb://{invalidIP}/");
Console.WriteLine($"exists? {smb4.Exists()}");`
Output:
SMB1 exists? True SMB2 exists? True SMB3 exists? True SMB4 exists? True
Non-existent devices should obviously lack SMB1/2/3/4 support