日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
LinuxC程序員看穿外網(wǎng)IP的迷霧(linuxc外網(wǎng)ip)

科技發(fā)展如此之快,我們身邊已經(jīng)有了許多高科技應(yīng)用了。一直以來(lái),穿越外網(wǎng)IP的迷霧一直是網(wǎng)絡(luò)安全研究的一塊重要課題,基于linux系統(tǒng)的C程序可以幫助你看穿迷霧,獲取到真實(shí)IP地址。

針對(duì)外網(wǎng)IP獲取,C程序員有幾種不同的方法和方案:

第一種方法是使用Epoll函數(shù)庫(kù),Epoll函數(shù)庫(kù)是Linux系統(tǒng)提供的一種高效的事件處理機(jī)制,可以判斷系統(tǒng)提交的新數(shù)據(jù),并處理之。在查詢外網(wǎng)IP時(shí),可以使用Epoll函數(shù)庫(kù),使用fd_set函數(shù)集查找Socket,然后使用gethostbyaddr函數(shù)獲取到對(duì)應(yīng)的地址信息:

#include

#include

#include

#include

#include

int main()

{

char * host=”xxx.xxx.xxx.xxx”;

int s;

int epfd;

struct hostent *hp;

struct epoll_event ev;

//Obtain a socket for web

int s = socket(AF_INET,SOCK_STREAM,0);

if(s == -1)

{

printf(“Create socket failed!”);

}

//configuring nameservers

struct hostent * hp = gethostbyaddr(host, strlen(host), AF_INET);

//Create epoll instance

epfd = epoll_create1(0);

if(epfd== -1)

{

perror(“epoll_create1() error”);

exit(1);

}

//Add the socket to epoll instance

ev.data.fd = s;

err=epoll_ctl(epfd, EPOLL_CTL_ADD,s, &ev);

if (err ==-1)

{

perror(“epoll_ctl() error”);

exit(1);

}

printf(“Getting External IP: %d.%d.%d.%d\n”, hptr->h_name, ptr->h_addrtype, ptr->h_length);

//Close socket

close(s);

return 0;

}

其次,C程序員也可以使用API或者Socket網(wǎng)絡(luò)編程技術(shù)來(lái)實(shí)現(xiàn)IP地址查找:在學(xué)習(xí)LinuxSocket編程時(shí),主要通過(guò)調(diào)用gethostbyname函數(shù)來(lái)查找地址對(duì)應(yīng)的IP地址:

#include

#include

#include

#include

int main()

{

char * hostname = “xxx.xxx.xxx.xxx”;

struct hostent*host_entry;

struct in_addr ipaddr;

int ret;

host_entry = gethostbyname(hostname);

ipaddr = *(struct in_addr *)(host_entry->h_addr);

printf(“%s: IP地址: %s\n”, hostname, inet_ntoa(ipaddr));

return 0;

}

同樣,C程序員還可以調(diào)用getaddrinfo函數(shù)來(lái)獲取對(duì)應(yīng)地址的IP地址,這個(gè)函數(shù)比gethostbyname更加靈活,可以在IPV4和IPV6之間設(shè)置類型,使用方式如下:

#include

#include

#include

#include

#include

int main(){

struct addrinfo hints, *res;

struct in_addr addr;

int errcode;

char addrstr[100];

void *ptr;

//Getting IP address from hostname

memset(&hints, 0, sizeof(hints));

hints.ai_family = PF_INET;

hints.ai_socktype = SOCK_STREAM;

hints.ai_flags |= AI_CANONNAME;

errcode = getaddrinfo(“www.example.com”, NULL, &hints, &res);

if (errcode != 0) {

printf(“getaddrinfo() failed: %s\n”, gai_strerror(errcode));

exit(1);

}

printf(“Host: %s\n”, res->ai_canonname);

ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;

inet_ntop(res->ai_family, ptr, addrstr, 100);

printf(“IPv4 address: %s\n”, addrstr);

freeaddrinfo(res);

}

通過(guò)以上三種方式,Linux C程序完全可以穿透外網(wǎng)IP的迷霧,查詢真實(shí)IP地址。然而,并不是所有的IP地址都可以直接被查詢到,有時(shí)候需要經(jīng)過(guò)幾次跳轉(zhuǎn)才能查詢到真實(shí)的IP地址,這也是想要深入了解IP地址信息時(shí),Linux C程序員必須要加強(qiáng)學(xué)習(xí)網(wǎng)絡(luò)安全技術(shù)的原因吧。

創(chuàng)新互聯(lián)-老牌IDC、云計(jì)算及IT信息化服務(wù)領(lǐng)域的服務(wù)供應(yīng)商,業(yè)務(wù)涵蓋IDC(互聯(lián)網(wǎng)數(shù)據(jù)中心)服務(wù)、云計(jì)算服務(wù)、IT信息化、AI算力租賃平臺(tái)(智算云),軟件開(kāi)發(fā),網(wǎng)站建設(shè),咨詢熱線:028-86922220


標(biāo)題名稱:LinuxC程序員看穿外網(wǎng)IP的迷霧(linuxc外網(wǎng)ip)
當(dāng)前路徑:http://m.5511xx.com/article/cccdsig.html