如何获得本地网络号(55分)

Q

QQ

Unregistered / Unconfirmed
GUEST, unregistred user!
如何获得本地的网络号
比如一个IP是200.100.100.1那么网络号是200.100.100
这个问题有两点:
1 获得本地IP
2 提取网络号
所有家当都在这里了!

如有现成答案请转贴!
 
Internet / TCPIP分类中有现成IP地址答案.
网络号你不是自己会算吗?
 
这里有个子网络化的问题,
也就是说, 网络号掩码不一定非得按照ABC几类来划分.

Windows中可以读注册表
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/NE20001/Parameters/Tcpip
下面的IPAddress和SubnetMask键值
这里的NE20001是从
HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/NetworkCards/1
下面的ServiceName键值得到的
如果有多个网卡, 一次取NetworkCards/2, 3, etc

UNIX中可以使用ifconfig界面
 
INTERNET TCP/IP分类?
我要的是本地网络号!

如果我不知道罔卡型号NE2000可能不正确(我用的不是NT),
有没有什么其它方法?

顺便问,关于TCP/IP编程的资料那里可以找到?(最好是DELPHI GB的,如果是C++
ENGLISH 的也可以)
 
对不起,我说的"INTERNET TCP/IP分类"是指论坛中的
这类问题,也就是我们现在讨论的问题的分类.

请在左边的Frame里选择"分类问题"
 
那个IPMAN我已经寄给你了,多少给我一点分吧!
 
好快,dwwang!刚才还没有看见你的贴子
 
没关系,如果ipman真的能解决问题(但应该是另一个问题:截取IP包),
分数当然应该给你(而且应该是200分).

而且我们还要管QQ要它"翻译"过来的IPMAN呢!
 
>QQ时间:98-11-4 04:06:28 下午

>我要的是本地网络号!

>如果我不知道罔卡型号NE2000可能不正确(我用的不是NT),
>有没有什么其它方法?
所谓本地网络号本来就是和Network Adapter Bind在一起的,
不是Windows NT的话, 请您自己在Win95注册表的相对应的
位置找找吧!

>有没有什么其它方法
没有标准的方法. 因为这不是Win API的功能, TCP/IP资料看了
也没用, 因为网络编程接口之类的东西都是对高层应用设计的,
象这样底层的问题(网卡以及协议配置)是由系统级的程序实现
的, 不同的系统, 实现起来有很大不同.

我有一些WinSocket的资料, 另外, 向你推荐若干网络编程书籍如下:
1. 用TCP/IP进行网际互连, 第三卷: 客户机-服务器编程和应用
(电子工业出版社, 国外计算机科学教材系列,16开, 绿色封面. 40.00 元)
(非常好, 强烈推荐!!)
2. UNIX环境下的网络程序设计
(学苑出版社, 16开, 蓝色封面, 23.00 元)
(介绍了几种典型的UNIX环境下的主要系统网络服务的实现, 很好!)
3. Unix Networking Programming Vol 1. Networking APIs: Sockets and XTI
(清华大学出版社, 32开, 影印版, 1010pages, 43.00 元)
(我怀疑上面那本书是抄袭这本书的某些章节而成的.)
4. 实用UNIX网络编程基础
(吉林科学技术出版社, 32开, 黑色插图封面, 6.00元)
(有几个生动有趣的例子, 还不错!)
5. Internet 编程
(电子工业出版社, 16开, 淡紫色封面, 58.00元, 含有软磁盘)
(主要讲了网络基础和Windows环境下Socket程序设计的思想和
一些客户端的实例, 如E-MAIL, FTP等. 教您如何进行探索!)
6. Windows Sockets 网络程序设计指南
(清华大学出版社, 32开, 8.80 元)
(对Windows 相关的问题进行了比较深入的讨论,)
 
你在那里买的?我怎么没有在书店看到过?
如果买到就给你加分!

顺便说:CJ的IPMAN我收到了,并且,附带了部分答案,CJ不要乱贴东西,正像
DWANG说的,你的答案是我提的另一个问题的答案!快去贴张帖子,我把分加给你!
 
不好意思,又搞错了!马上就去贴!
 
>你在那里买的?我怎么没有在书店看到过?
呵呵, 如果您也每个星期都逛遍全城的主要书店的话, :)
(如果在南京可以到新视角书店去买)
>如果买到就给你加分!
嘻嘻, 那就麻烦您跑跑腿, 买到后给我加分, :)
 
太远了吧!
 
pegasus我看样子这几个月不会去南京了,不过你能给我我提问题的程序,那么分数
还是你的!
 
您在哪个山头(城市, :)?
1, 2, 3, 5四本书都非常醒目, 好一些的计算机专业书店应该全有

上面介绍的方法应该可以很容易得到本地网络号呀!
唉, 您要是实在不肯自己动手, 那我就明天给您例子程序,
因为我还要找一台Win95看看注册表和NT的不同所在.
(不肯自己锻炼一下? 别的大侠别和我争分啦! :)
 
问题就在这里,很烦的!我在上海,平时也常常走书店,怎么从来没有看到过?
例子程序!多谢了!
 
Here is the example on NT; result in sIPAddress and sNetMask

Uses Registry;

procedure TestGettingIPAddressAndNetMask;
Var
regRootKey: TRegistry;
sNetCardRegKey: String;
sNetCardDriverName: String;
sServiceRegKey: String;
sTCPIPRegKey: String;
cIPAddressArray: array[1..256] of char;
sIPAddress : String;
cNetMaskArray: array [1..256] of char;
sNetMask: String;
i: Integer;
l: Integer;
begin
regRootKey := TRegistry.Create;
sNetCardRegKey := '/SOFTWARE/Microsoft/Windows NT/CurrentVersion/NetworkCards/1';
sServiceRegKey := '/SYSTEM/CurrentControlSet/Services/';
regRootKey.RootKey := HKEY_LOCAL_MACHINE;
regRootKey.OpenKeyReadOnly(SNetCardRegKey);
sNetCardDriverName := regRootKey.ReadString('ServiceName');

sTCPIPRegKey := sServiceRegKey + sNetCardDriverName + '/Parameters/Tcpip';

regRootKey.OpenKeyReadOnly(sTCPIPRegKey);

l := regRootKey.ReadBinaryData('IPAddress', cIPAddressArray, 255);
for i:=1 to l do begin
if cIPAddressArray<>#0 then
sIPAddress := sIPAddress + cIPAddressArray
else break;
end;

l := regRootKey.ReadBinaryData('SubNetMask', cNetMaskArray, 255);
for i:=1 to l do begin
if cNetMaskArray<>#0 then
sNetMask := sNetMask + cNetMaskArray
else break;
end;

regRootKey.Destroy;
end;
 
Here is example under Win95. A bit easier than under NT

Procedure GetIPAddressAndNetMaskExample;
Var
regRootKey: TRegistry;
sNetCardRegKey: String;
sNetCardDriverName: String;
sServiceRegKey: String;
sTCPIPRegKey: String;
sIPAddress : String;
sNetMask: String;
begin
regRootKey := TRegistry.Create;
sNetCardRegKey := '/Enum/Network/MSTCP/0001/';
sServiceRegKey := '/SYSTEM/CurrentControlSet/Services/Class/';

regRootKey.RootKey := HKEY_LOCAL_MACHINE;
regRootKey.OpenKeyReadOnly(SNetCardRegKey);
sNetCardDriverName := regRootKey.ReadString('Driver');

sTCPIPRegKey := sServiceRegKey + sNetCardDriverName;

regRootKey.OpenKeyReadOnly(sTCPIPRegKey);

sIPAddress := regRootKey.ReadString('IPAddress');
sNetMask := regRootKey.ReadString('IPMask');

regRootKey.Destroy;
end;
 
Here is some explanation to my demo code:

Q: Why code for 95 is too much late than the code for NT?
A: When I finished testing code for NT, and write code for 95, my
Delphi failed to compile my demo code, it always complained:
"Internal error", :(, I had to restart my machine.

Q: What's the main diffience under NT and 95?
A: 1. KeyPath and Value.
2. NT allows Multiple IPAddress to be bind into one interface,
so it can not use a string type to stroe the data. In fact, it is
a type called "strings", i.e., stores string by string, end with
a null string. ex. 'String1/0String2/0String3/0' is a strings
which contains 3 strings. So to the netmask storage.

Q: Any more comment?
A: 1. 'MSTCP' in example code for 95 is not general, it is the string
to describ that you are installing "Microsoft TCP/IP protocol", :)
2. If you have multiple netcards, then you can increase '0001'
in the code for 95 and '1' in the code for NT. And there might be
some network card interface not binded to TCP/IP protocol, of
course you can not get the address/netmask information of such
ones.
 
:pegasus,你真厉害,
QQ,我把一本关于WINSOCK的书寄给了你和斑竹!
多少给我点吧!5分也行!
不过除非必要否则还是用DELPHI 4的INTERNET控件好!
 

Similar threads

回复
0
查看
666
不得闲
回复
0
查看
812
不得闲
回复
0
查看
519
不得闲
回复
0
查看
653
不得闲
顶部