如何检查IP范围内的IP [英] How to Check IP in IP Range

查看:104
本文介绍了如何检查IP范围内的IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



i有两个问题



i有IP范围如10.20.30.0/ 24并搜索ip10.20.30.12



1.我需要找到范围的起始IP和结束IP

2。检查范围内的天气Ip。



我需要为IPV4和IPV6实施。



任何帮助, ??





谢谢

Joe

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

推荐答案

使用 IPAddress类 [ ^ ]



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
}





IPAddress.Address属性 [ ^ ]是一个长属性,一个64位整数 - 所以比较一个地址是否在一个范围内就像比较整数值一样容易。



最好的问候

Espen Harlinn



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


你可以阅读这篇文章:

http://www.dreamincode.net/forums/topic/24549-vbnet- find-all-ips-on-a-lan / [ ^ ]

PsychoCoder has一个很好的解决方案
You could read this article:
http://www.dreamincode.net/forums/topic/24549-vbnet-find-all-ips-on-a-lan/[^]
PsychoCoder has a nice solution


这篇关于如何检查IP范围内的IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆