I have tried a lot of solutions on internet for getting IP's from my local network and all of them have been failed to get all IP's. I also try to get IP's using ARP commands "arp /a" and "arp -a" but this command is also unable to do the job finally after searching for a while I found a software called "Advance IP Scanner" and when I run this software it gets all the IP's from local network and the most strange thing for me is that after running the Advance IP Scanner when I run the ARP command "arp /a" or "arp -a" it gets all the IP's from my local network.
This is what I have tried.
public List<IPScanEntity> GetArpResult()
{
List<IPScanEntity> List = new List<IPScanEntity>();
string baseIp = ConfigurationManager.AppSettings["baseIp"];
//getting my own system IP
List.Add(HostIPScanResult());
for (int subnet = 1; subnet < 255; subnet++)
{
bool a = List.Any(x => x.Ip.Equals(baseIp+subnet.ToString()));
if (a == true)
{
continue;
}
try
{
var p = Process.Start(new ProcessStartInfo("arp", "/a " + baseIp + subnet)
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true
});
var output = p?.StandardOutput.ReadToEnd();
p?.Close();
var lines = output.Split('\n').Where(l => !string.IsNullOrWhiteSpace(l));
if (!lines.Contains("No ARP Entries Found.\r"))
{
var result =
(from line in lines
select Regex.Split(line, @"\s+")
.Where(i => !string.IsNullOrWhiteSpace(i)).ToList()
into items
where items.Count == 3
select new IPScanEntity
{
Ip = items[0],
MacAddress = items[1],
});
List.Add(result.FirstOrDefault());
}
}
catch (Exception ex)
{
log.Error(ex.Message);
}
}
return List;
}