Get public/external IP address?

前端 未结 26 2232
鱼传尺愫
鱼传尺愫 2020-11-22 14:32

I cant seem to get or find information on finding my routers public IP? Is this because it cant be done this way and would have to get it from a website?

26条回答
  •  轮回少年
    2020-11-22 14:52

    Fast way to get External ip without any connection Actualy no need any Http connection for that

    first you must add NATUPNPLib.dll on Referance And select it from referances and check from properties window Embed Interop Type to False

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using NATUPNPLib; // Add this dll from referance and chande Embed Interop Interop to false from properties panel on visual studio
    using System.Net;
    
    namespace Client
    {
        class NATTRAVERSAL
        {
            //This is code for get external ip
            private void NAT_TRAVERSAL_ACT()
            {
                UPnPNATClass uPnP = new UPnPNATClass();
                IStaticPortMappingCollection map = uPnP.StaticPortMappingCollection;
    
                foreach (IStaticPortMapping item in map)
                {
                        Debug.Print(item.ExternalIPAddress); //This line will give you external ip as string
                        break;
                }
            }
        }
    }
    

提交回复
热议问题