當前位置:首頁 » 編程語言 » c語言ipconfig
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言ipconfig

發布時間: 2023-03-20 06:18:23

1. 如何用c語言獲取網卡的mac地址

為什麼一定要用C語跡坦言呢帶運?這個用C語言比較麻煩,需要的知識比較多,完全可以用更簡單的辦法啊。命令行上這樣的命令「ipconfig -all | find "物理地姿行桐址"」,可以很簡單的就得到了。
如果是英文系統, 將「物理地址」換成「Physical Address」即可。
如果非的要用C語言,則可以先調用system函數, system("ipconfig -all | find \"物理地址\" > temp.txt" ); 將mac地址信息存入臨時文件temp.txt;然後再從中提取。

2. 怎麼將ipconfig/all裡面的內容顯示出來,並取出IP地址值。(用C語言)

/* 編譯環境: visual c++ */
#include <stdio.h>
#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")
int doit(int, char **)
{
char host_name[255];
/滲態/獲取本地主機名稱
if (gethostname(host_name, sizeof(host_name)) == SOCKET_ERROR) {
printf("Error %d when getting local host name.n", WSAGetLastError());
return 1;
}
printf("Host name is: %sn", host_name);
//從主機名資料庫中得到對應的「主機」
struct hostent *phe = gethostbyname(host_name);
if (phe == 0) {
printf("Yow! Bad host lookup.");
return 1;
}
//循環得出本地機器所有IP地址叢悔源
for (int i = 0; phe->h_addr_list[i] != 0; ++i) {
struct in_addr addr;
memcpy(&addr, phe->h_addr_list[i], sizeof(struct in_addr));
printf("Address %d : %sn" , i, inet_ntoa(addr));
}
return 0;
}
int main(int argc, char *argv[])
{
WSAData wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
return 255;
}
前春int retval = doit(argc, argv);
WSACleanup();
return retval;
}

3. C語言如何實現IP地址查詢系統

C語言如何實現IP地址查詢系統
參考如下:

voidGetNameAndIp()
{
structhostent*host;
structin_addr*ptr;
DWORDdwScope=RESOURCE_CONTEXT;
NETRESOURCE*NetResource=NULL;
HANDLEhEnum;
WNetOpenEnum(dwScope,NULL,NULL,NULL,&hEnum);
WSADATAwsaData;
WSAStartup(MAKEWORD(1,1),&wsaData);
if(hEnum)
{
DWORDCount=0xFFFFFFFF;
DWORDBufferSize=10240;
LPVOIDBuffer=newchar[10240];
WNetEnumResource(hEnum,&Count,Buffer,&BufferSize);
NetResource=(NETRESOURCE*)Buffer;
charszHostName[200];
for(unsignedinti=0;i<BufferSize/sizeof(NETRESOURCE);i++,NetResource++)
{
if(NetResource->dwUsage==RESOURCEUSAGE_CONTAINER&&NetResource->dwType==RESOURCETYPE_ANY)
{
if(NetResource->lpRemoteName)
{
CStringstrFullName=NetResource->lpRemoteName;
if(0==strFullName.Left(2).Compare(_T("\\")))
strFullName=strFullName.Right(strFullName.GetLength()-2);
gethostname(szHostName,strlen(szHostName));
USES_CONVERSION;
char*pchar=T2A(strFullName);
host=gethostbyname(pchar);
if(host==NULL)continue;
ptr=(structin_addr*)host->h_addr_list[0];
stringstr="";
for(intn=0;n<4;n++)
{
CStringaddr;
if(n>0)
{
str+=".";
}
intvalue=(unsignedint)((unsignedchar*)host->h_addr_list[0])[n];
charp[20];
sprintf(p,"%d",value);
str.append(p);
}
std::cout<<"IP:"<<str<<"Name:"<<host->h_name<<std::endl;
}
}
}
deleteBuffer;
WNetCloseEnum(hEnum);
}
WSACleanup();
}

4. 怎樣通過C語言修改系統IP

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 50
typedef struct
{
char eth[N], ip[N], netmasks[20], gw[N], dns[N], tag[N];
}data;
int main()
{
data list[]=
{
{
"本地連接",
"222.22.65.173", //IP地址
"255.255.255.128",//子網掩碼
"222.22.65.129",//默認網關
"202.196.64.1",//首選DNS伺服器地址
"LAB"//這個配置的標簽
},
{
"本地連接",
"10.108.8.89",
"255.255.255.0",
"10.108.8.1",
"202.196.64.1",
"寢室"
}
};
int i, num=sizeof(list)/sizeof(data);
char temp[200], set[200];
for(i=0; i<num; i++)
printf("%d %s\n", i+1, list[i].tag);
printf("\n輸入需要修改至的IP編號\n");
while( scanf("%d", &i)!=1 || i>num || i<=0);
i--;

sprintf(set, "netsh interface ip set address \"%s\" static %s %s %s >nul",
list[i].eth, list[i].ip, list[i].netmasks, list[i].gw);
sprintf(temp, "& netsh interface ip set dns \"%s\" static %s & ipconfig & pause",
list[i].eth, list[i].dns);
strcat(set, temp);
system(set);
return 0;
}

5. C語言有一個已排好序的整型數組,有10個元素,要求從鍵盤輸入一個數後,按原來排序的規律將它插入數組中

源代碼如下:

#include <stdlib.h>

#include <stdio.h>

int main()

{

int a[20],i,n,x,k;

printf("請輸入一組順序數(從小到大的順序):");

for( i=0; ;i++ )

{

scanf("%d",&a[i]);

if( getchar() == ' ' )

break;

}

n = i + 1; //n表示數組內數字的個數

printf("請輸入需要插入的數:");

scanf("%d",&x);

for(i=0;i<n;i++)

{

if( x<= a[i] )

{

for( k= n-1; k >= i; k--)

{

a[k+1]=a[k];

}

a[i]=x;

break;

}

}

for(i=0;i<=n; i++)

{

printf("%d ",a[i]);

}

printf(" ");

system("pause");

}

(5)c語言ipconfig擴展閱讀

1、C語言支持數組數據結構,它可以存儲一個固定大小的相同類型元素的順序集合。數組是用來存儲一系列數據,但它往往被認為是一系列相同類型的變數。

2、數組的聲明並不是聲明一個個單獨的變數,比如 number0、number1、...、number99,而是聲明一個數組變數。

6. Hi,您知道C語言如何調用DOS命令 如:ipconfig | find 「17」

解:
system("ipconfig
|
find
\"17\"
");
在C語言里雙引號內特殊字元用反斜杠"\"表示,如引號輸入\",兩個引號輸入\手嫌"\",反斜杠本身\\等
LZ該不會不知燃嫌道"\n"皮薯手吧?