当前位置:网站首页>Obtain the home location through IP
Obtain the home location through IP
2022-07-19 08:13:00 【qq_ eight hundred and fifty-seven million three hundred and fiv】
ip.plyz.net Provides ip Query function , Just send one get Just ask
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#include <WinSock2.h>
#include <iostream>
#include <stdio.h>
#include <string>
#pragma comment(lib,"Ws2_32.lib")
using namespace std;
int UTF82GBK(char* szUtf8, char* szGbk, int Len)
{
int n = MultiByteToWideChar(CP_UTF8, 0, szUtf8, -1, NULL, 0);
WCHAR* wszGBK = new WCHAR[sizeof(WCHAR) * n];
memset(wszGBK, 0, sizeof(WCHAR) * n);
MultiByteToWideChar(CP_UTF8, 0, szUtf8, -1, wszGBK, n);
n = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL);
if (n > Len)
{
delete[]wszGBK;
return -1;
}
WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, szGbk, n, NULL, NULL);
delete[]wszGBK;
wszGBK = NULL;
return 0;
}
bool getinfo()
{
bool Ret = false;
const char* hostname = "ip.plyz.net";
struct hostent* host = gethostbyname(hostname);
if (host==nullptr)
{
return false;
}
/* Initialize a structure that connects to the server */
sockaddr_in serveraddr;
serveraddr.sin_family = AF_INET;
serveraddr.sin_port = htons(80);
/* You don't have to do this here , Don't need to use gethostbyname, Put the website ping once , obtain IP It's OK, too */
serveraddr.sin_addr.S_un.S_addr = *((int*)*host->h_addr_list);
int sock = socket(AF_INET, SOCK_STREAM, 0);
do
{
if (sock == -1)
{
break;
}
if (::connect(sock, (struct sockaddr*)&serveraddr, sizeof(sockaddr_in)) == -1)
{
break;
}
/* GET request */
const char* bufSned = "GET http://ip.plyz.net/ip.ashx?ip=myip\r\n";
/* send out GET request */
if (send(sock, bufSned, strlen(bufSned), 0) == 0)
{
break;
}
char BufRecv[100] = {
};
int nLen = 0;
string HtmlData;
/* Start receiving data */
while ((nLen = recv(sock, BufRecv, 100, 0)) > 0)
{
/* Splice an array into string type , To facilitate the following processing */
HtmlData += BufRecv;
}
char data[100] = {
0 };
UTF82GBK(BufRecv, data, 100);
Ret = true;
printf("BufRecv=%s\n", data);
} while (false);
if (sock!=INVALID_SOCKET)
{
closesocket(sock);
}
return Ret;
}
int main()
{
/* initialization */
WSADATA wsdata;
WSAStartup(MAKEWORD(1, 1), &wsdata);
getinfo();
return 0;
}
边栏推荐
- [C# Console]-C# 控制台类
- 812. 最大三角形面积
- csp-2020-6-《角色授权》
- How does the V8 engine recycle garbage memory?
- Redis jump table implementation principle & time complexity analysis
- [C classes and objects] - Methods and class and object programming in C
- DP动态规划企业级模板分析(数字三角,上升序列,背包,状态机,压缩DP)
- Deep learning 7 deep feedforward network 2
- Ccf-csp "202206-2 - treasure hunt! Adventure!"
- 行为型模式之策略模式
猜你喜欢

并发编程的核心问题

2022 review questions and mock exams for main principals of hazardous chemical business units

深度学习之 7 深度前馈网络

RNN convolutional neural network

Xinlinx zynq7010 domestic replacement fmql10s400 national production arm core board + expansion board
![[C# 变量常量关键字]- C# 中的变量常量以及关键字](/img/9b/433f9110d9c7599d8beac8288ea409.png)
[C# 变量常量关键字]- C# 中的变量常量以及关键字

代码学习(DeamNet)CVPR | Adaptive Consistency Prior based Deep Network for Image Denoising

演示集合注入

Jira --- workflow call external api

Practice of online problem feedback module (V): realize the automatic filling function of general field content
随机推荐
C语言一个数如果恰好等于它的因子之和,这个数就称为“完数”。例如6=1+2+3.编程
Ku115 FPGA high performance 10G Optical fiber network hardware accelerator card / 2-way 10G Optical fiber data accelerator card
【Kernel】驱动开发学习之字符设备
数组习题三
What if the user information in the website app database is leaked and tampered with
Error received from peer ipv4/Connection reset by peer Paddleserving服务化部署后报错
Shenzhen Prudential written examination record
MCU如何选型?
Deep learning 7 deep feedforward network 2
[C# Console]-C# 控制臺類
Double index mechanism of redis source code analysis
unity 自定义天空球模型防止被裁剪
leetcode:287. 寻找重复数【快慢指针板子】
Pytorch notes (5)
RISC-V技術雜談
Xilinx ultrascale+ MPSoC (zu9eg/zu15eg) high performance PCIe data preprocessing board
Jira --- workflow call external api
Beijing Jiewen technology, an acquiring outsourcing service provider, transferred 60% of its shares for about 480million
从 B 站崩溃报告看分布式系统的技术栈
Paddleserving服务化部署 tensorrt报错, shape of trt subgraph is [-1,-1,768],