• 06-04-2020, 02:03:46
    #1
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Local ip için ;
    1. foreach (IPAddress ıPAddress in Dns.GetHostAddresses(Dns.GetHostName()))
    2. {
    3. Console.WriteLine("tespit edilen ip adresi:"+ ıPAddress);
    4. }
    External IP için ise;
    1. string disIp = new WebClient().DownloadString("http://icanhazip.com");
    2. Console.WriteLine("Dış Ip Adresi "+disIp);
    kodlarını kullandım. ama siteye yüklediğimde iki IP adreside aynı çıkıyor hatta sitenin yüklü olduğu ip adresini gösteriyor ikisi de neden olur ?
    Nasıl düzeltebilirm?

    Teşekkürler.
  • 06-04-2020, 05:31:23
    #2
    besnoktadort adlı üyeden alıntı: mesajı görüntüle
    Local ip için ;
    1. foreach (IPAddress ıPAddress in Dns.GetHostAddresses(Dns.GetHostName()))
    2. {
    3. Console.WriteLine("tespit edilen ip adresi:"+ ıPAddress);
    4. }
    External IP için ise;
    1. string disIp = new WebClient().DownloadString("http://icanhazip.com");
    2. Console.WriteLine("Dış Ip Adresi "+disIp);
    kodlarını kullandım. ama siteye yüklediğimde iki IP adreside aynı çıkıyor hatta sitenin yüklü olduğu ip adresini gösteriyor ikisi de neden olur ?
    Nasıl düzeltebilirm?

    Teşekkürler.
    string PublicIP = new WebClient().DownloadString("https://ipinfo.io/ip");
    var HostDevice = Dns.GetHostEntry(Dns.GetHostName());
    var PrivateIP = HostDevice.AddressList.FirstOrDefault(IP => IP.AddressFamily == AddressFamily.InterNetwork);
                MessageBox.Show(String.Format("Public IP : {0}\nPrivate IP : {1}",PublicIP,PrivateIP));
    Hocam bu sorunuzu çözebilir.
  • 06-04-2020, 14:54:53
    #3
    SwenenzY adlı üyeden alıntı: mesajı görüntüle
    string PublicIP = new WebClient().DownloadString("https://ipinfo.io/ip");
    var HostDevice = Dns.GetHostEntry(Dns.GetHostName());
    var PrivateIP = HostDevice.AddressList.FirstOrDefault(IP => IP.AddressFamily == AddressFamily.InterNetwork);
                MessageBox.Show(String.Format("Public IP : {0}\nPrivate IP : {1}",PublicIP,PrivateIP));
    Hocam bu sorunuzu çözebilir.
    Denedim gene olmadı siteye attığımda websitesinin ip adresini gösteriyor. Teşekkürler yinede
  • 06-04-2020, 14:58:04
    #4
    🌐 𝘀𝗼𝗰𝗶𝗳𝗹𝘆.𝗰𝗼𝗺
    Request.ServerVariables("LOCAL_ADDR") - Lokal IP'yi bununla alabilirsin.
  • 06-04-2020, 15:52:57
    #5
    besnoktadort adlı üyeden alıntı: mesajı görüntüle
    Denedim gene olmadı siteye attığımda websitesinin ip adresini gösteriyor. Teşekkürler yinede
    WebRequest ile tamamını okuyabilirsin? istersen örnek atabilirim.



    besnoktadort adlı üyeden alıntı: mesajı görüntüle
    Denedim gene olmadı siteye attığımda websitesinin ip adresini gösteriyor. Teşekkürler yinede
    /* Çözüm 1 */
    string Country;
    string PublicIP;
    string CC;
    try
    {
    string Url = "https://api.myip.com/";
    HttpWebRequest Request = WebRequest.Create(Url) as HttpWebRequest;
    string JsonData = "";
    using (HttpWebResponse Response = Request.GetResponse() as HttpWebResponse)
    {
    StreamReader Reader = new StreamReader(Response.GetResponseStream());
    JsonData = Reader.ReadToEnd();
    JObject MyParser = JObject.Parse(JsonData);
    PublicIP = (string)MyParser["ip"];
    Country = (string)MyParser["country"];
    CC = (string)MyParser["cc"];
    MessageBox.Show(String.Format("Country : {0},PublicIP : {1},CC : {2}",Country,PublicIP,CC));
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show("Error : " + ex.Message);
    }
    /* Çözüm 2 */
    try
    {
    string Url = "https://ipinfo.io/ip";
    string Data = "";
    Data = new StreamReader(((WebRequest.Create(Url) as HttpWebRequest).GetResponse() as HttpWebResponse)
    .GetResponseStream()).ReadToEnd();
    
    MessageBox.Show(String.Format("Data : {0}", Data));
    
    }
    catch (Exception ex)
    {
    MessageBox.Show("Error : " + ex.Message);
                }

    Umarım bu yardımcı olur.
  • 06-04-2020, 21:29:37
    #6
    En son aşağıdaki kodlar ile yapabildim. localhost ta ::1 gözüküyordu ama canlıya aldığımda IP adresini gösteriyor.
            
    public static string GetUserIP()
    {
    var IP = string.Empty;
    
    if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
    IP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
    else if (HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"] != null && HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"].Length != 0)
    IP = HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"];
    else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
    IP = HttpContext.Current.Request.UserHostName;
    return IP;
            }