开发者

About the ip check with ipv4 and ipv6

开发者 https://www.devze.com 2023-03-18 01:52 出处:网络
I have a ip check in my source use csharp. And now, I must to think about the check rule about theipv4 and ipv6.

I have a ip check in my source use csharp.

And now, I must to think about the check rule about the ipv4 and ipv6.

The client side maybe like ↓

・only ipv4

・only ipv6

・both ipv4 and ipv6

Im sorry , Im new to the networking .

As so , Is anybody could give me some suggestion about the ip check?

Thanks.

About the IP Check:

I have a check like ↓ now :

bool isgoodip() 
{
  return ip.startwith(173); 
}

If the client side has only the ipv6 , ho开发者_如何学Gow can I do the check like this ?

and , is there has a server setting can convert the ipv6 to the ipv4 auto ?


Using Statements

using System.Net;
using System.Net.Sockets;

IP Checking Code

IPAddress address = IPAddress.Parse("127.0.0.1");

if (address.AddressFamily == AddressFamily.InterNetwork) // IPv4
{
    // do ipv4 stuff here
}

if (address.AddressFamily == AddressFamily.InterNetworkV6) // IPv6
{
    // do ipv6 stuff here
}

if ((address.AddressFamily == AddressFamily.InterNetwork) || (address.AddressFamily == AddressFamily.InterNetworkV6)) // IPv4 and IPv6
{
    // do both ipv4 and ipv6 stuff here
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号