Chinaunix首页 | 论坛 | 博客
  • 博客访问: 651676
  • 博文数量: 329
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 693
  • 用 户 组: 普通用户
  • 注册时间: 2015-01-05 23:37
个人简介

Do not panic!

文章存档

2021年(1)

2018年(3)

2017年(7)

2016年(98)

2015年(220)

我的朋友

分类: LINUX

2016-07-04 08:48:25

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    char *s = NULL;
    s=getenv("REMOTE_ADDR");

    printf("Content-type: text/plain;\n\n");
   
    if(s!=NULL)
     printf("ip: %s\n",s); 

    else
     printf("%s\n", "s is null");
 
   return 0;
}

 

这个是获得客户端ip的,通过getenv这个函数还可以获得以下一些东东

   "REMOTE_ADDR",
                "DOCUMENT_ROOT",
                "GATEWAY_INTERFACE",
                "SERVER_SOFTWARE",
                "SERVER_NAME",
                "SERVER_PROTOCOL",
                "SERVER_PORT",
                "SERVER_ADMIN",
                "SERVER_SIGNATURE",
                "REQUEST_METHOD",
                "REQUEST_URI",
                "PATH_INFO",
                "PATH_TRANSLATED",
                "SCRIPT_NAME",
                "SCRIPT_FILENAME",
                "QUERY_STRING",
                "REMOTE_HOST",
                "REMOTE_ADDR",
                "REMOTE_USER",
                "REMOTE_IDENT",
                "CONTENT_TYPE",
                "CONTENT_LENGTH",
                "HTTP_ACCEPT",
                "HTTP_ACCEPT_CHARSET",
                "HTTP_ACCEPT_LANGUAGE",
                "HTTP_ENCODING",
                "HTTP_USER_AGENT",
                "HTTP_CONNECTION",
                "HTTP_HOST",
                "HTTP_REFERER",
                "AUTH_TYPE"

阅读(653) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~