本文介绍了如何使用vb在asp.net中获取ip,子网,网关,首选和备用DNS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我尝试获取服务器机器的ip,子网,网关,首选和备用dns,并使用vb在asp.net的文本框中显示。

请发送一些代码示例来获取服务器机器ip,子网,网关,首选和备用DNS并显示在单独的文本框中。



我已经更改了配置asp.net中的服务器机器
在asp.net中更改IP,子网,网关,DNS(首选和备用)[]



因此,在进行更改之前,我需要向用户显示正确的详细信息。





请尽快回复



问候

Aravind

Hi
I am try to get ip,subnet,gateway,preferred and alternate dns for server machine and show in textbox in asp.net using vb.
pls send some code samples to fetch server machine ip,subnet,gateway,preferred and alternate DNS and show in separate textboxes.

Already i did change config for server machine in asp.net
How to change IP,Subnet,Gateway,DNS(Prefers and alternate) in asp.net using vb[^]

So before going to change,i need to show correct details to users.


Pls reply asap

Regards
Aravind

推荐答案

For Each ni As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces()
    If ni.OperationalStatus <> OperationalStatus.Up Then 
        ' The interface is disabled; skip it.
        Continue For
    End If
    
    Console.WriteLine(ni.Name)
    
    Dim ipProp As IPInterfaceProperties = ni.GetIPProperties()
    
    For Each ip As UnicastIPAddressInformation In ipProp.UnicastAddresses
        If ip.Address.AddressFamily <> AddressFamily.InterNetwork Then
            ' The IP address is not an IPv4 address.
            Continue For
        End If
        
        Console.WriteLine("IP address: {0}", ip.Address)
        Console.WriteLine("Subnet mask: {0}", ip.IPv4Mask)
        Exit For
    Next
    
    For Each gateway As GatewayIPAddressInformation In ipProp.GatewayAddresses
        If gateway.Address.AddressFamily <> AddressFamily.InterNetwork Then
            ' The gateway address is not an IPv4 address.
            Continue For
        End If
        
        Console.WriteLine("Default gateway: {0}", gateway.Address)
        Exit For
    Next
    
    Console.WriteLine("DNS servers:")
    For Each ip As IPAddress In ipProp.DnsAddresses
        Console.WriteLine(ip)
    Next
    
    Exit For
Next





请记住,计算机可能有多个网络接口,每个接口可能有多个IP地址和多个DNS服务器。本地IP地址可能包含IPv6地址,这些地址没有子网掩码。



Remember that the computer could have multiple network interfaces, and each interface could have multiple IP addresses and multiple DNS servers. The local IP addresses might include IPv6 addresses, which won't have a subnet mask.



这篇关于如何使用vb在asp.net中获取ip,子网,网关,首选和备用DNS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 23:26