Login
Register
Tutorials
Forum
Career Development
Resources
Reviews
Jobs
Interview
Communities
Projects
Training
Silverlight Games
|
Bookmarks
|
New Members FAQ
|
Mentor
|
Code Converter
|
IT Companies
|
Peer Appraisal
|
Members
|
Revenue Sharing
|
Computer Jokes
|
New Posts
|
Social
|
Online Members
ankita
More...
Forums
»
.NET
»
.NET
»
ip address textbox in c#
Posted Date:
27 Jun 2008
Posted By::
Imran Ahmed khan
Member Level:
Silver
Member Rank:
0
Points
: 1
Responses:
4
hi,
plz give me the code for ipaddress textbox in C#.
give me the step also
thanks
Tweet
Responses
#256434 Author:
R.M.Phani Kumar
Member Level:
Gold
Member Rank:
1643
Date: 27/Jun/2008 Rating:
Points
: 0
Ip Adress means?????????
#256444 Author:
Imran Ahmed khan
Member Level:
Silver
Member Rank:
0
Date: 27/Jun/2008 Rating:
Points
: 0
i what in this form 192.25.122.111
#256454 Author:
Mastan
Member Level:
Bronze
Member Rank:
5564
Date: 27/Jun/2008 Rating:
Points
: 6
Check Local IP Address [C#]
This example shows how to detect whether a host name or IP address belongs to local computer.
Get local computer name
Get local computer host name using static method Dns.GetHostName.
[C#]
string localComputerName = Dns.GetHostName();
Get local IP address list
Get list of computer IP addresses using static method Dns.GetHostAddresses. To get list of local IP addresses pass local computer name as a parameter to the method.
[C#]
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
Check whether an IP address is local
The following method checks if a given host name or IP address is local. First, it gets all IP addresses of the given host, then it gets all IP addresses of the local computer and finally it compares both lists. If any host IP equals to any of local IPs, the host is a local IP. It also checks whether the host is a loopback address (localhost / 127.0.0.1).
[C#]
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;
}
You can test the method for example like this:
[C#]
IsLocalIpAddress("localhost"); // true (loopback name)
IsLocalIpAddress("127.0.0.1"); // true (loopback IP)
IsLocalIpAddress("MyNotebook"); // true (my computer name)
IsLocalIpAddress("192.168.0.1"); // true (my IP)
IsLocalIpAddress("NonExistingName"); // false (non existing computer name)
IsLocalIpAddress("99.0.0.1"); // false (non existing IP in my net)
or you can refer http://msdn.microsoft.com/en-us/library/system.net.ipaddress_members.aspx
#256468 Author:
Imran Ahmed khan
Member Level:
Silver
Member Rank:
0
Date: 27/Jun/2008 Rating:
Points
: 0
just i want text box ti act as
111.22.222.222
Post Reply
This thread is locked for new responses. Please post your comments and questions as a
separate thread
.
If required, refer to the URL of this page in your
new post
.
Tweet
Next :
print the data present in the window form...urgent
Previous :
Doubt...
Return to Discussion Forum
Post New Message
Category:
Related Messages
Is there any expert to solve this?
what is difference between String and string(data type) in c#?
what is a resource file...
Horizontal Scroll Bar for a listview control
sql querry
Active Members
Today
Prachi Kulkarn...
(37)
Hemanth
(25)
Prasad kulkarn...
(25)
Last 7 Days
Naved Hasan ...
(255)
naveensanagase...
(230)
Pawan Awasthi
(176)
more...
Awards & Gifts
Email subscription
.NET Jobs
.NET Articles
.NET Forums
Articles Rss Feeds
Forum Rss Feeds
Talk to Webmaster Tony John