当前位置:首页 » 编程语言 » 通过c语言查询路由器ip
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

通过c语言查询路由器ip

发布时间: 2023-02-21 03:55:08

c语言查询本机ip地址的程序

#include <windows.h>
#include <winsock2.h>

❷ 用C语言编写程序如何获得外网的IP的地址

//通过ip138网站来查询外网IP的
#include <afxinet.h>
void CLanChatDlg::GetNetIP()
{

SetDlgItemText(IDC_NET_IP,"正在获取外网IP");
CString strsource;
CString Address;
CInternetSession mySession(NULL,0);
CHttpFile* myHttpFile=NULL;

Address="http://www.ip138.com/ip2city.asp";//ip138网页

myHttpFile=(CHttpFile*)mySession.OpenURL(Address);//读取网络地址

while(myHttpFile->ReadString(strsource))
{ //循环读取下载来的网页文本
// AddToLog(strsource);
int begin=0;
begin=strsource.Find("[",0);

if(begin!=-1)//如果找到"[", 则找"]" 中括号内的文本则是 你的外网ip
{ int end=strsource.Find("]");
m_internetip=strsource.Mid(begin+1,end-begin-1);//提取外网ip

SetDlgItemText(IDC_NET_IP,m_internetip);//在左下角显示外网ip
}
}

❸ 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();
}

❹ c语言ip判断

#include<stdio.h>
structIP
{
inta;
charq1;
intb;
charq2;
intc;
charq3;
intd;
}s;
voidyesno()
{
scanf("%d%c%d%c%d%c%d",&s.a,&s.q1,&s.b,&s.q2,&s.c,&s.q3,&s.d);
if(s.a<256&&s.a>0&&s.b<256&&s.b>0&&s.c<256&&s.c>0&&s.d<256&&s.d>0)
{
if(s.q1=='.'&&s.q1=='.'&&s.q1=='.')printf("YES ");
elseprintf("NO ");
}
elseprintf("NO ");
}

main()
{
inti;
for(i=0;i<99;i++)
{yesno();}
}

❺ c#怎么获取路由器的ip地址,求代码

using System.Text;
using System.Net;
using System.Text.RegularExpressions;
using System.IO;
public class Router
{
Encoding gb2312 = Encoding.GetEncoding(936);//路由器的web管理系统默认编码为gb2312
/// <summary>
/// 使用HttpWebRequest对象发送请求
/// </summary>
/// <param name="url"></param>
/// <param name="encoding">编码</param>
/// <param name="cache">凭证</param>
/// <returns></returns>
private static string SendRequest(string url, Encoding encoding,CredentialCache cache)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
if (cache != null)
{
request.PreAuthenticate = true;
request.Credentials = cache;
}
string html = null;
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader srd = new StreamReader(response.GetResponseStream(), encoding);
html = srd.ReadToEnd();
srd.Close();
response.Close();
}
catch (Exception ex) { html = "FALSE" + ex.Message; }
return html;
}
/// <summary>
/// 获取路由MAC和外网IP地址
/// </summary>
/// <param name="RouterIP">路由IP地址,就是网关地址了,默认192.168.1.1</param>
/// <param name="UserName">用户名</param>
/// <param name="Passowrd">密码</param>
/// <returns></returns>
private string LoadMACWanIP(string RouterIP,string UserName,string Passowrd)
{
CredentialCache cache = new CredentialCache();
string url = "http://" + RouterIP + "/userRpm/StatusRpm.htm";
cache.Add(new Uri(url), "Basic", new NetworkCredential(UserName, Passowrd));
return SendRequest(url, gb2312, cache);
}
}

❻ 只用C语言,怎么通过域名得到IP地址

查找的方法(07版为例): 1、在左下方开始键,点击之后出现搜索框 2、在搜索框内输入指令cmd运行 3、进入窗口,按照要求输入指令:nbtstat -a IP,ip地址为你所查询主机的ip地址。 4、这样就可以根据ip泛解析出域名。

❼ 请问 , 用c语言怎样获取ip地址啊 谢谢了

看你要获得那里的ip地址
如果是本及机的话,就使用windows的API啊

#include "winsock.h"
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
char* ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
// ip is ready
WSACleanup( );
}

❽ 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();
}