如何获得并修改本机的IP,网关与DNS??一百九十分!!!!!

alwssoan 2001-07-11 02:31:59
如何获得并修改本机的IP,网关与DNS,重要的是如何修改,给出方法,最好是源代码!修改,修改!!好的答案可另外开档加分,我的最高只能给190
...全文
638 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
linzhai 2001-07-12
  • 打赏
  • 举报
回复
老兄: tcp/ip dns 網關都保存在注冊表,不管你用什么方法,改的都是注冊, 不過你可以用程式來修改注冊嗎, 98 nt 2000 加入一個判斷就行了,只是多幾行代碼而已.
kks 2001-07-11
  • 打赏
  • 举报
回复
从MSDN找到的,有空在给你试一下吧
改IP地址可以用AddIPAddress
DWORD AddIPAddress(
IPAddr Address // IP address to add
IPMask IpMask //subnet mask for IP address
DWORD IfIndex // index of adapter
PULONG NTEContext // Net Table Entry context
PULONG NTEInstance // Net Table Entry Instance );

改网关:

PMIB_IPFORWARDTABLE pIpForwardTable = NULL;
PMIB_IPFORWARDROW pRow = NULL;
ULONG dwSize = 0;
BOOL bOrder = FALSE;
DWORD dwStatus = 0;
DWORD NewGateway = 0xDDBBCCAA; // this is in host order Ip Address AA.BB.CC.DD is DDCCBBAA

// Find out how big our buffer needs to be
dwStatus = GetIpForwardTable(pIpForwardTable, &dwSize, bOrder);
if (dwStatus == ERROR_INSUFFICIENT_BUFFER) {

// Allocate the memory for the table
if (!(pIpForwardTable = (PMIB_IPFORWARDTABLE)malloc(dwSize))) {
OutputMessage(TEXT("Malloc failed, Out of Memory!\r\n"));
exit(1);
}

// Now get the table
dwStatus = GetIpForwardTable(pIpForwardTable, &dwSize, bOrder);
}

if (dwStatus != ERROR_SUCCESS) {
OutputMessage(TEXT("GetIpForwardTable Failed, ERROR %d\r\n"), dwStatus);
if (pIpForwardTable)
free(pIpForwardTable);
exit(1);
}

// Search for the row in the table we want. The default gateway has a destination
// of 0.0.0.0 - Notice that we continue looking through the table, but only copy
// one row. This is so that if there happen to be multiple default gateways, we can
// be sure to delete them all.
for (unsigned long int i=0; i < pIpForwardTable->dwNumEntries; i++) {
if (pIpForwardTable->table[i].dwForwardDest == 0) {

// We've found the default gateway
if (!pRow) {
// Allocate some memory to store the row in - this is easier than filling
// in the row structure ourselves and we can be sure we only change the
// gateway address.
pRow = (PMIB_IPFORWARDROW)malloc(sizeof(MIB_IPFORWARDROW));
if (!pRow) {
OutputMessage(TEXT("Malloc failed, Out of Memory!\r\n"));
exit(1);
}
// Copy the row
memcpy(pRow, &(pIpForwardTable->table[i]), sizeof(MIB_IPFORWARDROW));
}

// Delete the old default gateway entry
dwStatus = DeleteIpForwardEntry(&(pIpForwardTable->table[i]));

if (dwStatus != ERROR_SUCCESS) {
OutputMessage(TEXT("Could not delete old gateway\n"));
exit(1);
}
}
}

// Set the nexthop field to our new gateway - all the other properties of the route will
// be the same as they were previously.
pRow->dwForwardNextHop = NewGateway;

// Create a new route entry for the default gateway.
dwStatus = CreateIpForwardEntry(pRow);

if (dwStatus == NO_ERROR)
OutputMessage(TEXT("Gateway changed successfully\n"));
else if (dwStatus == ERROR_INVALID_PARAMETER)
OutputMessage(TEXT("Invalid Parameter\n"));
else
DisplayErrorMessage(dwStatus);

// Free resources
if (pIpForwardTable)
free(pIpForwardTable);
if (pRow)
free(pRow);

月光 2001-07-11
  • 打赏
  • 举报
回复
只有改注册表,改完好像要发个更新注册表的api.
Kingron 2001-07-11
  • 打赏
  • 举报
回复
>>注册表的不要,只要程序修改的,

用程序修改注册表不就行了?不要告诉我连用程序修改注册表都不准?其实都是控制注册表来进行系统配置的,不过修改之后,可能要重新启动哦。
alwssoan 2001-07-11
  • 打赏
  • 举报
回复
取得的不要,只要修改的。注册表的不要,只要程序修改的,因为注册表不同平台下是有所不同的
取得的不要,只要修改的。注册表的不要,只要程序修改的,因为注册表不同平台下是有所不同的
linzhai 2001-07-11
  • 打赏
  • 举报
回复
非常簡單,
在注冊表中有 ip 地址, 網關, dns , 你想怎麼改都可以,不要告訴我你不會修改注冊表.

要我告訴你也可以,不過...
wljcr 2001-07-11
  • 打赏
  • 举报
回复
gz
hof 2001-07-11
  • 打赏
  • 举报
回复
用api gethostname得到机器名,在用机器名调用gethostbyname得到本机的ip
设置应该有gethostname和sethostbyname
具体你自己找一下吧, 挺忙的, 呵
machin 2001-07-11
  • 打赏
  • 举报
回复
PowerSock1 有个LocalIp的属性.

edit1.text := PowerSock1.LocalIp;

其他的我没试过....
路人丁 2001-07-11
  • 打赏
  • 举报
回复
Powersock控件可以获得本机ip
if (Powersock1->LocalIP == "0.0.0.0")
ShowMessage("not connected");
else
ShowMessage(Powersock1->LocalIP);
内容概要:本文系统研究了构网型变流器的正负序阻抗解耦特性及其在弱电网环境下的稳定性表现,重点依托Matlab/Simulink仿真平台,构建了详细的阻抗数学模型,设计了解耦控制策略,并采用小信号扫频法进行频域辨识与稳定性验证。研究深入探讨了构网型变流器与传统跟网型逆变器在正负序阻抗特性上的本质差异,结合虚拟同步发电机(VSG)等先进控制技术,析其在抑制宽频带振荡、削弱锁相环动态耦合等方面的优越性。文中不仅提供了完整的仿真模型与MATLAB代码实现,还整合了光伏、风电、储能、微电网等多类新能源系统的阻抗建模与稳定性析资源,形成了一套面向新型电力系统稳定性的综合性技术资料体系,具有较强的科研复现与工程参考价值。; 适合人群:面向具备电力电子、电力系统自动化、新能源并网等专业背景的研究生、高校教师及工程技术人员,特别适用于从事阻抗建模、小干扰稳定性析、宽频振荡机理研究以及撰写高水平学术论文的科研工作者。; 使用场景及目标:①掌握构网型变流器正负序阻抗建模与扫频辨识的仿真方法;②深入理解VSG等构网型控制在弱电网中提升稳定性的内在机理;③复现顶刊论文中的阻抗析流程与稳定性判据应用;④利用提供的成熟模型与代码加速科研进程,支撑课题研究与学术成果产出。; 阅读建议:建议结合文中提供的Simulink模型与MATLAB代码,按照“理论建模—仿真搭建—扫频激励—频响提取—Nyquist判据析”的完整流程进行实践操作,重点关注扫频信号的注入方式、频率范围设置及阻抗曲线的物理意义解读,并参考博士论文复现案例深化对复杂动态耦合问题的理解。

5,943

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧