Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

i have two questions

i have IP Range like "10.20.30.0/24" and search ip "10.20.30.12"

1. i need to find start IP and End IP of the Range
2. Check weather Ip inside range.

I need to implement for IPV4 and IPV6.

any help,??


Thanks
Joe
Posted

Use the IPAddress Class[^]

IPAddress.Parse( "fe80::21c:42ff:fe00:8%vnic0" );
IPAddress.Parse( "127.0.0.1" );


// AddressFamily.InterNetworkV6 indicates an ipv6 address
if( IPAddress.Parse("127.0.0.1").AddressFamily == AddressFamily.InterNetwork ) 
{
  //You've get an ipv4 address
}


The IPAddress.Address Property[^] is a long property, a 64 bit integer - so comparing whether an address is in a range is as easy as comparing integer values.

Best regards
Espen Harlinn
 
Share this answer
 
Comments
fjdiewornncalwe 15-Feb-13 9:30am    
My 5.
Espen Harlinn 15-Feb-13 9:48am    
Thank you, Marcus :-D
You could read this article:
http://www.dreamincode.net/forums/topic/24549-vbnet-find-all-ips-on-a-lan/[^]
PsychoCoder has a nice solution
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900