为什么不显示“SHOW PROCESSLIST”?给主机IP?
我在客户端应用程序上执行“SHOW PROCESSLIST”。
它给出输出:
,它在其中一行中显示为“WIN-R2VUKMIS1PR:54822”
当我查看主机列时 我是否知道主机 IP 是什么“WIN-R2VUKMIS1PR:54822”...
我正在编写执行“SHOW PROCESSLIST”的 ac 程序 并显示所有连接主机的输出。
那么如何将主机名解析为IP呢?我尝试使用
这里是我用来将“WIN-R2VUKMIS1PR:54822”转换为IP的演示应用程序:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char *argv[ ]) {
struct hostent *h;
/* error check the command line */
if(argc != 2) {
fprintf(stderr, "Usage: %s hostname\n", argv[0]);
exit(1);
}
/* get the host info */
if((h=gethostbyname(argv[1])) == NULL) {
herror("gethostbyname(): ");
exit(1);
}
else {
printf("Hostname: %s\n", h->h_name);
printf("IP Address: %s\n", inet_ntoa(*((struct in_addr *)h->h_addr)));}
return 0;
}
我错过了什么吗? :-)
I execute "SHOW PROCESSLIST" on the client App.
it gives the Output:
When I look at Host column it displays in one of the row as "WIN-R2VUKMIS1PR:54822"
How do I get to know what the host IP is "WIN-R2VUKMIS1PR:54822"...
I am writing a c program that executes "SHOW PROCESSLIST"
and displays the output of all connected hosts.
So how do I resolve the Host name to IP? I tried using
Here is the demo app I used to convert "WIN-R2VUKMIS1PR:54822" to IP:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char *argv[ ]) {
struct hostent *h;
/* error check the command line */
if(argc != 2) {
fprintf(stderr, "Usage: %s hostname\n", argv[0]);
exit(1);
}
/* get the host info */
if((h=gethostbyname(argv[1])) == NULL) {
herror("gethostbyname(): ");
exit(1);
}
else {
printf("Hostname: %s\n", h->h_name);
printf("IP Address: %s\n", inet_ntoa(*((struct in_addr *)h->h_addr)));}
return 0;
}
Am I missing something? :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 gethostbyname_r -- 查找与主机名匹配的网络主机数据库条目。
但请注意,它已被弃用。如果您的应用程序即将上线,请务必小心。
另外,我不确定它是否可以帮助你。
You may use gethostbyname_r -- find network host database entry matching host name.
But note it is deprecated. So careful if your app is going live.
Also, I am not sure whether it might help you.