網域名稱轉IP例程

2021-07-25 03:48:00 字數 1201 閱讀 4496

struct hostent *gethostbyname(const char *name);

這個函式的傳入值是網域名稱或者主機名,例如"www.google.cn"等等。傳出值,是乙個hostent的結構。如果函式呼叫失敗,將返回null。

struct hostent ; 

hostent->h_name

表示的是主機的規範名。例如www.google.com的規範名其實是www.l.google.com。

hostent->h_aliases

表示的是主機的別名.www.google.com就是google他自己的別名。有的時候,有的主機可能有好幾個別名,這些,其實都是為了易於使用者記憶而為自己的**多取的名字。

hostent->h_addrtype     

表示的是主機ip位址的型別,到底是ipv4(af_inet),還是pv6(af_inet6)

hostent->h_length       

表示的是主機ip位址的長度

hostent->h_addr_lisst 

表示的是主機的ip位址,注意,這個是以網路位元組序儲存的。千萬不要直接用printf帶%s引數來打這個東西,會有問題的哇。所以到真正需要列印出這個ip的話,需要呼叫inet_ntop()。

const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) :

這個函式,是將型別為af的網路位址結構src,轉換成主機序的字串形式,存放在長度為cnt的字串中。返回指向dst的乙個指標。如果函式呼叫錯誤,返回值是null。

#include #include 

#include

int main(int argc, char **argv)

printf(

"official hostname:%s\n

",hptr->h_name);

for(pptr = hptr->h_aliases; *pptr != null; pptr++)

printf(

"alias:%s\n

",*pptr);

printf(

"addrtype:%d\n

",hptr->h_addrtype);

switch(hptr->h_addrtype)

return0;

}

iOS網域名稱轉解析為IP

網域名稱解析為ip 這裡介紹下小得技能點 nsstring realmtoip nsstring hostname nsstring getipaddressbyhostname nsstring strhostname catch n ception e struct in addr ip add...

網域名稱轉ip位址程式設計實現

linux平台 首先ip位址在程式設計中有兩種形式,一種是十進位制點分式,如192.168.2.187,另外一種是用乙個32位的整數表示 ipv4 struct hostent typedef uint32 t in addr t struct in addr 解釋一下 h name 位址的正式名稱...

DNA 批量網域名稱轉IP程式使用方法

最近做的一些工作出了與3d開發有關,還涉及到了黑客攻防,所以寫乙個程式輔助一下 如何快速的蒐集想要的資訊,也是黑客技術水平的體現 下面是程式的使用方法 搜尋出結果後複製鏈結位址 然後做你想要的操作,你可以選擇是否包括搜尋引擎子站鏈結在內 所有結果都是唯一的,也就是排除了重複的網域名稱 網域名稱換ip...