當前位置:首頁 » 雲伺服器 » socket怎麼查伺服器ip

socket怎麼查伺服器ip

發布時間: 2023-04-27 07:00:00

① vb.net socket中的當客戶端連接Server的時候怎麼取得客戶端的IP地址

1.綁定的ip是伺服器的ip地址,伺服器是固定的,客戶端連接的是一個已知的伺服器端。
2.客戶端的話,連接到伺服器時,伺服器accept後,就可以獲得客戶端的連接信息,包括ip地址和埠。
我是學c的,在c語言中,socket->bind->listen->accept->....,在accept函數中有選項,如下caddr結構體中就存有accept後客戶端的ip地址
連接埠和傳輸方式等信息,clientsock[1]則為accept新的描述符,如你程序中soc2一樣

clientsock[1]
=
accept(sfd,(struct
sockaddr*)&caddr,&len);
vb中應該也有類時的函數,你網上好好找一下,或者看看相關書籍.

java 如何從收到的socket中取得IP

java中從Socket中獲取IP地址通過Socket的getInetAddress()方法即可獲得Socket中的Ip地址。其中Socket中還可以通過getLocalAddress()獲取Socket綁定的本地地址。

php用socket獲得客戶端的ip和埠

socket_getpeername() 獲取遠程類似主機的ip地址
socket_getsockname() 獲取本地socket的ip地址
怎麼感覺你用的實際上是對的,難道用nginx一類的負載均衡伺服器了

④ tcpsocket本地有多個ip,如何知道哪個ip連接了伺服器

桌面,開始段飢,運行,輸入cmd然後點回車,輸入all再點回車,顯示出來的敗賣信息就是ip協議的設置。我們新建一個tcpsocket連接伺服器,看看本機是用哪個ip去連接的,這個ip就是電腦連接tcpsocket的。察燃逗

⑤ 想要用socket連接一個另一個網路中的內網地址如何知道他的ip

通常內網地址DMZ區,通常無法直伏殲接訪吵森問。
需要中間有伺服器中轉。
如果能控制另一個網路路由器,可以做埠指向,這個有點麻煩。
就是你的IP是192.168.1.10,網關是192.168.1.1,另一個缺碰沖網路IP是192.168.2.10,網關是192.168.2.1
192.168.1.1和192.168.2.1可能是一個L2的不同網口,也可能是一個伺服器的兩個網卡。
情況不一樣,做法不一樣。

⑥ mfc socket客戶端怎麼知道伺服器的ip

因為Client是通信的主動方,即發起通信的一端,因此通信之前Client必須已知Server的IP和埠號才行。
通常的C/S模式通信的做法是先為Server申請公網IP,然後在client編程時指明欲連接的Server的IP和埠號,這樣的client程序一旦安裝後就內置了Server的IP;
另一種做法是在client的執行界面預留輸入框,執行時允許用戶輸入Server的IP,然後實現通信,這兩種方式都必須事先知道server的IP信息才行。

⑦ Java編寫socket程序時,怎麼知道伺服器在整個網路上的IP地址

這個恐怕要到伺服器查才能知道~~就像玩私.服~伺服器改了IP~~會公布新IP給玩家更改客戶端的伺服器IP~~如果你的不是互聯網,而是區域網~就可以向你所在的區域網中所有IP都發個信息,那個有回應,那個就是伺服器~這是一個笨方法。。。

⑧ 如何獲得Socket連接客戶端的IP地址

如果伺服器端要獲取客戶端ip的話:


//假設socket(),bind(),listen()函數已經完成
addrlen=sizeof(client);
connetfd=accept(listenfd,(structsockaddr*)&client,&addrlen);

那麼client.sin_port 就是客戶端的埠

client.sin_addr.s_addr 就是客戶端的ip。

這兩個都是以網路位元組序來保存的,如果要printf的話需要先轉化為主機位元組序

⑨ 能否通過socket獲取本機IP地址,子網掩碼,或者是網卡名稱

可以實現的,使用ioctl函數,加上想獲得的選項即可。
正好手頭有個類似的例子:
=======================================================
#include <stdio.h>#include <sys/types.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <net/if_arp.h>
#include <arpa/inet.h>
#include <unistd.h>

#define MAXINTERFACES 16
int main(int argc, char **argv){
register int fd, interface, retn = 0;
struct ifreq buf[MAXINTERFACES];
struct arpreq arp;
struct ifconf ifc;
char mac[32] = "";

if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) >碧岩雀= 0) { ifc.ifc_len = sizeof buf;
ifc.ifc_buf = (caddr_t) buf;
if (!ioctl(fd, SIOCGIFCONF, (char *) &ifc)) {
interface = ifc.ifc_len / sizeof(struct ifreq);
printf("interface num is interface=%d\n\n", interface);
while (interface-- > 0) {
printf("net device %s\n", buf[interface].ifr_name);
/*Jugde whether the net card status is promisc */

if (!(ioctl(fd, SIOCGIFFLAGS, (char *) &buf[interface]))) { if (buf[interface].ifr_flags & IFF_PROMISC) {
printf("the interface is PROMISC");
return 0;
}
} else {
char str[256] = "";
sprintf(str, "cpm: ioctl device %s",buf[interface].ifr_name);
perror(str);
}

/*Jugde whether the net card status is up */ if (buf[interface].ifr_flags & IFF_UP) {
printf("the interface status is UP\n");
} else {
printf("the interface status is DOWN\n");
}

/悔早*Get IP of the net card */棗汪 if (!(ioctl(fd, SIOCGIFADDR, (char *) &buf[interface]))) {
printf("IP address is:");
printf("%s\n", inet_ntoa(((struct sockaddr_in*) (&buf[interface].ifr_addr))->sin_addr));
} else {
char str[256] = "";
sprintf(str, "cpm: ioctl device %s",buf[interface].ifr_name);
perror(str);
}

/*Get HW ADDRESS of the net card */ if (!(ioctl(fd, SIOCGIFHWADDR, (char *) &buf[interface]))) {
printf("HW address is:");
sprintf(mac, "%02x%02x%02x%02x%02x%02x",
(unsigned char) buf[interface].ifr_hwaddr.sa_data[0],
(unsigned char) buf[interface].ifr_hwaddr.sa_data[1],
(unsigned char) buf[interface].ifr_hwaddr.sa_data[2],
(unsigned char) buf[interface].ifr_hwaddr.sa_data[3],
(unsigned char) buf[interface].ifr_hwaddr.sa_data[4],
(unsigned char) buf[interface].ifr_hwaddr.sa_data[5]); // 利用sprintf轉換成char *
printf("%s\n", mac);
printf("\n");
}
else {
char str[256];
sprintf(str, "cpm: ioctl device %s",buf[interface].ifr_name);
perror(str);
}
} //end of while
} else
perror("cpm: ioctl");
} else
perror("cpm: socket");
close(fd);
return retn;
}
==============================================
輸出:
[root@temp]$./deleteme interface num is interface=2
net device eth0the interface status is UP
IP address is:10.6.15.102
HW address is:005056a44485

net device lothe interface status is UP
IP address is:127.0.0.1
HW address is:000000000000

⑩ 怎麼獲取socket ip 地址

你是想知道代碼還是想了解原理,一般的C/S模型都由客戶端發出連接請求(客戶端在代碼中都是存有伺服器端的具體ip地址和埠信息(也就是伺服器端的INET協議族地址結構)的),當客戶端發送連接請求後,伺服器端通過accpet函數接收連接請求,accpet函數示例:accept(ServerSocket,(structsockaddr*)&from,&len)(from是一個INET協議族地址結構變數,(structsockaddr*)的作用是把INET協議族地址結構強制轉換為通用地址結構),accpet函數在接收連接的同時會把客戶端的具體ip和埠信息賦值給from,所以說客戶端socket連接的ip(非綁定的話客戶機隨機綁定ip和埠)是包含在連接報文數據里,伺服器端只有接收到客戶端發送的連接信息後,才會獲得客戶端的ip和埠信息,獲得具體ip的方式是通過函數,這個函數可以提取出IPv4地址結構中的點分十進制地址,函數用法:inet_ntoa(from.sin_addr)。

熱點內容
php開發php開發 發布:2025-05-10 10:37:49 瀏覽:859
伺服器地址s開頭 發布:2025-05-10 10:36:59 瀏覽:839
為什麼賬號風險不能修改密碼 發布:2025-05-10 10:31:23 瀏覽:67
sql與in相對 發布:2025-05-10 10:31:15 瀏覽:223
c語言led燈閃爍 發布:2025-05-10 10:26:54 瀏覽:812
比爾密碼價值多少人民幣 發布:2025-05-10 10:26:20 瀏覽:448
怎樣用電腦遠程連接撥號伺服器 發布:2025-05-10 10:17:44 瀏覽:467
伺服器需要什麼系統 發布:2025-05-10 10:17:38 瀏覽:195
中國電信拍攝腳本 發布:2025-05-10 10:17:00 瀏覽:457
43魔獸世界POR腳本 發布:2025-05-10 10:06:15 瀏覽:731