none
Read/Write Multiple static IPv4 Address with Subnet Prefix from network device in Advanced TCP/IP Settings RRS feed

  • Question

  • Hi All,
    I need to do the below tasks from WCF service for the network device (Connected/Disconnected network device Adapter)

    • Read/Write list of static IPv4 Address with Subnet Prefix length
    • Read/Write list of static IPv4 Default Gateway address with Metric

    Is there any API available, for performing the above operations?.



    Friday, January 11, 2019 5:52 AM

All replies

  • Hi Navaneethapperumal,

    Do you want to read the client IP address information? As far as I know, we could refer to the following code snippets.

        public class MyService : IService
        {
            public string ReadClientIP()
            {
                OperationContext context = OperationContext.Current;
                MessageProperties properties = context.IncomingMessageProperties;
                RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                var result=endpoint.Address + ":" + endpoint.Port.ToString();
                Console.WriteLine(result);
                return result;
            }
    }

    There seems to be no native implementation for IPv6 addressing. But you can use the code below to get the native IPV6 address locally.

    string name = Dns.GetHostName();
    IPAddress[] ipadrlist = Dns.GetHostAddresses(name);
    foreach (IPAddress ipa in ipadrlist)
    {
        if (ipa.AddressFamily == AddressFamily.InterNetworkV6)
            Console.Writeline(ipa.ToString());
    }
    
    

    For processing network programming, we could use the following C# class library.

    IPAddress/IPEndPoint System.net namespace (system.dll assembly) 
    Ping/PingOptions/PingReply System.net.NetworkInformation(system.dll assembly)
    Here are msdn library links.
    https://docs.microsoft.com/en-us/dotnet/api/system.net.ipaddress?view=netframework-4.7.2

    https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.channels.remoteendpointmessageproperty?redirectedfrom=MSDN&view=netframework-4.7.2

    Feel free to let me know if there is anything I can help you.

    Best Regards
    Abraham


    Friday, January 11, 2019 9:36 AM
    Moderator