TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to Check Local IP Address
Manoj Bhoir
Apr 21
2015
Code
1.4
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
public
static
bool
IsLocalIpAddress(
string
host)
{
try
{
// get host IP addresses
IPAddress[] hostIPs = Dns.GetHostAddresses(host);
// get local IP addresses
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
// test if any host IP equals to any local IP or to localhost
foreach
(IPAddress hostIP
in
hostIPs)
{
// is localhost
if
(IPAddress.IsLoopback(hostIP))
return
true
;
// is local address
foreach
(IPAddress localIP
in
localIPs)
{
if
(hostIP.Equals(localIP))
return
true
;
}
}
}
catch
{ }
return
false
;
}
C#
C#.NET
Local IP
Networking