我需要帮助从网页获取第一行,找到一个与ipchicken.com合作的小脚本。 但我不能用我的网页脚本运行它,发布原始代码因为我对所有事情都很生气......为此! 我在这里搜索,但我没有找到,我发布了一个问题..
但需要正确编辑才能使用我的PHP脚本.. php> file.php?get = ver或ip on 192.168.1.1 port 88
switch($_GET['get'])
{
case "ip" :
echo ($_SERVER['REMOTE_ADDR']);
break;
case "ver" :
print "0.1.1";
break;
default :
break;
}
这是原始的c ++代码>
char *getwebpage(char *hostname, char *uri, unsigned long *total)
{
if(!hostname || !uri || !total) return (char *)0;
*total = 0;
char *headers1 = "Accept: text/html, */*\nAccept-Language: en-GB\nAccept-Encoding: none\nHost: ";
char *headers2 = (char *)malloc(strlen(headers1) + strlen(hostname) + 2);
sprintf(headers2, "%s%s\n", headers1, hostname);
HINTERNET session = InternetOpen("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
HINTERNET connect = InternetConnect(session, hostname, 80, "", "", INTERNET_SERVICE_HTTP, 0, 0);
HINTERNET http = HttpOpenRequest(connect, "GET", uri, HTTP_VERSION, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);
HttpSendRequest(http, headers2, strlen(headers2), NULL, 0);
free(headers2);
unsigned long read;
char buffer[1024];
char *final = (char *)malloc(1024);
memset(buffer, 0, 1024);
while(InternetReadFile(http, buffer, 1024, &read) && (read != 0)){
CopyMemory((final + *total), buffer, read);
*total += read;
final = (char *)realloc(final, (*total + 1024));
memset((final + *total), 0, 1024);
}
InternetCloseHandle(http);
InternetCloseHandle(connect);
InternetCloseHandle(session);
return final;
}
int getmyipaddress(char *buffer)
{
unsigned long length;
char *webpage = getwebpage("www.ipchicken.com", "/", &length);
if(!webpage || length == 0) return 0;
int result = 0;
char *start = strstr(webpage, "<b>");
if(start){
start += 3;
while(*start <= ' ') start++;
char *end = start;
while(*end > ' ') end++;
*end = 0;
strcpy(buffer, start);
result = 1;
}
free(webpage);
return result;
}
和..是的,如何添加像这样的端口选择 - &gt;
char *getwebpage(char *hostname, char *uri, char *port, unsigned long *total)
HINTERNET connect = InternetConnect(session, hostname, port, "", "", INTERNET_SERVICE_HTTP, 0, 0);
答案 0 :(得分:1)
您说您的服务位于端口88,但您致电:
HINTERNET connect = InternetConnect(session, hostname, 80, ....
所以也许改成:
HINTERNET connect = InternetConnect(session, hostname, 88, ....
答案 1 :(得分:0)
尝试使用InternetReadFile(http,&amp; buffer,1024和&amp; read)。我不确定这是否会解决您的问题,但我确信在函数InternetReadFile()调用中必须有一个指向缓冲区的指针