#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
>
#ifdef solaris
#include
<
sys/
sockio.h
>
#endif
#define
maxinte***ces 16
main (argc, argv)
register
intargc;
register
char
*argv; }
else //
判斷網絡卡狀態
if(buf[int***ce].ifr_flags
&iff_up)
else //
獲取當前網絡卡的ip位址 if(
!(ioctl (fd, siocgifaddr, (
char*)
&buf[int***ce])))
else /*
this section can't get hardware address,i don't know whether the reason is module driver
*/#ifdef solaris
//獲取mac位址
arp.arp_pa.sa_family
=af_inet;
arp.arp_ha.sa_family
=af_inet;
((struct
sockaddr_in*)
&arp.arp_pa)
->
sin_addr.s_addr=((
struct
sockaddr_in*)(
&buf[int***ce].ifr_addr))
->
sin_addr.s_addr; if(
!(ioctl (fd, siocgarp, (
char*)
&arp)))
#else
#if0
/*get hw address of the net card
*/if(!
(ioctl (fd, siocgenaddr, (
char*)
&buf[int***ce])))
#endifif(
!(ioctl (fd, siocgifhwaddr, (
char*)
&buf[int***ce])))
#endif
else }
//while
} else
perror (
"cpm: ioctl
");
} else
perror (
"cpm: socket
");
close (fd);
return
retn; }
設定指定ip和自動獲取ip
1.設定指定固定ip的bat檔案 echo off echo 開始設定 netsh inte ce ip set address name 本地連線 source static addr 192.168.1.2 mask 255.255.255.0 gateway 192.168.1.1 gwmet...
c 獲取本地ip和外網ip
ctest.cpp 此檔案包含 main 函式。程式執行將在此處開始並結束。include include include define max size 1024 pragma comment lib,urlmon.lib pragma comment lib,ws2 32.lib include...
Winform獲取本地IP和外網IP
一.本地ip winform要獲得本地ip,就要想到c 中的 iphostentry 類 好吧,方法如下 引入命名空間 using system.net 實現方法 iphostentry iphost dns.resolve dns.gethostname ipaddress ipaddress i...