I have to get the Router/GateWay IP and then incrementing the last octet everytime to scan all the devices.I get the GateWay IP using a function NetworkGateway()
.
//gets the GateWay IP
string gate_ip= NetworkGateway();
//mechanism to parse ,get the last octet and increment it everytime goes here so that ping_var = "192.168.0" + "." + i; have a fixed "192.168.0"
for (int i = 2; i <= 255; i++)
{
//changes i for every unique device
string ping_var = "192.168.0" + "." + i;
}
IPAddress address = IPAddress.Parse(ipAddress);
// gives 192.168.0.1 when passed "192.168.0.1 "
Console.WriteLine("Parsing your input string: " + "\"" + ipAddress + "\"" + " produces this address (shown in its standard notation): "+ address.ToString());
//Returns the Bytes of IP
Byte[] bytes = address.GetAddressBytes();
for (int i = 0; i < bytes.Length; i++)
{
Console.Write(bytes[i]);
}
For this purpose I used firstly IPAddress.Parse(ipAddress)
and then GetAddressBytes()
but it just returned xxxxxxxx
which couldn't be used for incrementing.
The AddOne
method suggested here at SO also didn't return it.
Any good idea.