zoukankan      html  css  js  c++  java
  • .net获取ip地址

    /// 获得客户端IP
        ///
        /// <returns></returns>
        private string getIp()
        {
            // 穿过代理服务器取远程用户真实IP地址
            string Ip = string.Empty;
            if (Request.ServerVariables["HTTP_VIA"] != null)
            {
                if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] == null)
                {
                    if (Request.ServerVariables["HTTP_CLIENT_IP"] != null)
                        Ip = Request.ServerVariables["HTTP_CLIENT_IP"].ToString();
                    else
                        if (Request.ServerVariables["REMOTE_ADDR"] != null)
                            Ip = Request.ServerVariables["REMOTE_ADDR"].ToString();
                        else
                            Ip = "202.96.134.133";
                }
                else
                    Ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
            }
            else if (Request.ServerVariables["REMOTE_ADDR"] != null)
            {
                Ip = Request.ServerVariables["REMOTE_ADDR"].ToString();
            }
            else
            {
                Ip = "202.96.134.133";
            }
            return Ip;
        }

    //控制台应用程序

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string hostName = Dns.GetHostName(); //获取本机主机名
                Console.WriteLine("Local hostname: {0}", hostName);
                IPHostEntry myself = Dns.GetHostEntry(hostName);//获取本机ip地址信息
                foreach (IPAddress address in myself.AddressList)
                {
                    Console.WriteLine("IP Address: {0}", address.ToString());
                }

            }
        }
    }

  • 相关阅读:
    如何设置'REUSE_ALV_GRID_DISPLAY'的单个单元格的颜色
    ABAP绘图功能模块概观(转)
    [数据库基础]——编码标准之编码注意事项(持续更新)
    ABAP--关于ABAP流程处理的一些命令的说明(stop,exit,return,check,reject)
    ABAP中的Table Control编程
    ABAP中的数据校验-备注
    ABAP 一个隐藏 selection-screen block的实例
    ABAP语言常用的系统字段及函数
    ABAP中的同步和异步调用
    FOR ALL ENTRIES IN 与 INNER JOIN 写在一个SQL上影响效率
  • 原文地址:https://www.cnblogs.com/skyshenwei/p/1677013.html
Copyright © 2011-2022 走看看