I just wanna get local ip address without using dns.getHostName Method
private string GetIpAddress(){
if(Regex.IsMatch(Dns.GetHostName(), @"^\d")){
throw new Exception("Begin with Alphabet in HostName")
}
IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
foreach(IPAddress address in ipEntry.AddressList){
if(address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork){
return address.Tostring();
}
}
}
In Some kind of User Systems, HostName(computer name) has to be composed with number and alphabet. but nowadays some user systems are permitted that hostname could only have number.
My Client Program get local ip by using getHostName() method. But getHostName() cannot get hostname when hostname has only number.
So I just wanna another way to get local ip address.
Please help me.