根據主機名獲得IP及根據IP獲得主機名

2021-05-12 20:08:09 字數 709 閱讀 9740

根據主機名獲得ip好說,前面已經學習過了,用函式gethostbyname獲得主機資訊,其中包括ip資訊

int cneighbordlg::getipbyname()

afxmessagebox(_t(list));

return 0;

}else

}根據ip獲得主機資訊則要用gethostbyaddr函式

int cneighbordlg::getnamebyip(cstring addr)

hostent *hostinfo;

hostinfo = gethostbyaddr((char*)(&a), strlen(addr), af_inet); //應該是有問題,外部網無法獲得。

if(hostinfo != null)

int err = wsagetlasterror();

if(err == wsano_data)

cstring strerr;

strerr.format("%d",err);

afxmessagebox(_t(strerr));

return 1;

}這一部分有乙個問題,就是有注釋的地方,實驗的時候獲得某些機器是沒問題的,而獲得另外一些就會有

問題,上網查了下原因,大體上是這樣的,此函式是netbios協議裡的,而某些機器上是沒有開啟此協議的,所以就無法獲得。時間關係,沒有驗證此說法的正確與否,以後再尋解決辦法。

獲得主機的IP和主機名

g o gethostip gethostip.cpp include include include include include include include include include define maxinte ces 16 define int int define char c...

區域網跨網段根據主機名找IP

本例需要被找的機器同時也在執行以下 目前是遍歷所有ip進行查詢,效率很低,在沒找到更好的辦法之前只好用它了。在區域網 lan 裡面根據主機名找到對應的ip。資訊描述 public class iphostinlan catch ioexception e finally catch exceptio...

linux修改主機名及ip

檢視主機名 hostname 修改主機名 重啟後無效 hostname hadoop 修改主機名 重啟後永久生效 vi ect sysconfig network 修改ip 重啟後無效 ifconfig eth0 192.168.12.22 修改ip 重啟後永久生效 vi etc sysconfig...