2

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 , how can I do the check like this ?

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

shenhengbin
  • 4,236
  • 1
  • 24
  • 33
  • There's no "conversion" from IPv6 to IPv4-- they are completely independent systems. I also don't see what use this kind of check provides. – Joe Jul 07 '11 at 02:49

1 Answers1

6

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
}
Nahydrin
  • 13,197
  • 12
  • 59
  • 101