请教关于网络的相关源程序!

jinjiahuli 2003-08-19 06:13:30
为什么用.net取ip地址时很慢??如何取子网掩码,网关,dns???请给出源程序或是相关思路。。。谢谢!!
...全文
22 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ruanyuping 2003-08-21
  • 打赏
  • 举报
回复
up
jinjiahuli 2003-08-21
  • 打赏
  • 举报
回复
老兄。。你提供的网址打不开
Montaque 2003-08-20
  • 打赏
  • 举报
回复
http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&selm=%24MxWIN87BHA.1532%40cpmsftngxa08&rnum=3

http://groups.google.com/groups?selm=eeeD%24NrxAHA.2188%40tkmsftngp02
Montaque 2003-08-20
  • 打赏
  • 举报
回复


Here is the VB.net code which displays the information of ipconfig /all
which includes the MAC address of the machine. This will work on Windows 98
and higher and windows 2000 and higher. It makes use of Ip helper api's
GetNetworkParams and GetAdapterInfo() api


Here is the code
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-----------------------------------------
'=====================================================================
' File: IPConfig.vb

' Summary: Demonstrates how to programatically retrieve IP configuration
' information by invoking native win32 API's using unmanaged code
' in C#. The output is very similar to IPCONFIG.EXE utility.

'---------------------------------------------------------------------
' This file is part of the Microsoft .NET Framework SDK Code Samples.

' Copyright (C) 2000 Microsoft Corporation. All rights reserved.

'This source code is intended only as a supplement to Microsoft
'Development Tools and/or on-line documentation. See these other
'materials for detailed information regarding Microsoft code samples.

'THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
'KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
'IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'PARTICULAR PURPOSE.
'=====================================================================


'Add the following namespaces
Imports System
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Threading
Imports Microsoft.VisualBasic.Constants
Imports Microsoft.VisualBasic.Conversion


'Constants used in the program as defined in IPExport.h and WinError.h
Public Class IPConfigConst
Public Const MAX_ADAPTER_NAME As Integer = 128
Public Const MAX_HOSTNAME_LEN As Integer = 128
Public Const MAX_DOMAIN_NAME_LEN As Integer = 128
Public Const MAX_SCOPE_ID_LEN As Integer = 256
Public Const MAX_ADAPTER_DESCRIPTION_LENGTH As Integer = 128
Public Const MAX_ADAPTER_NAME_LENGTH As Integer = 256
Public Const MAX_ADAPTER_ADDRESS_LENGTH As Integer = 8
Public Const DEFAULT_MINIMUM_ENTITIES As Integer = 32

Public Const ERROR_BUFFER_OVERFLOW As Integer = 111
Public Const ERROR_SUCCESS As Integer = 0
End Class


'Different Adapter types as defined in IPifcons.h
Public Class IPAdapterTypes
Public Const MIB_IF_TYPE_OTHER As Integer = 1
Public Const MIB_IF_TYPE_ETHERNET As Integer = 6
Public Const MIB_IF_TYPE_TOKENRING As Integer = 9
Public Const MIB_IF_TYPE_FDDI As Integer = 15
Public Const MIB_IF_TYPE_PPP As Integer = 23
Public Const MIB_IF_TYPE_LOOPBACK As Integer = 24
Public Const MIB_IF_TYPE_SLIP As Integer = 28
End Class


'typedef struct _IP_ADAPTER_INFO
'{
' struct _IP_ADAPTER_INFO* Next;
' DWORD ComboIndex;
' char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
' char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
' UINT AddressLength;
' BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];
' DWORD Index;
' UINT Type;
' UINT DhcpEnabled;
' PIP_ADDR_STRING CurrentIpAddress;
' IP_ADDR_STRING IpAddressList;
' IP_ADDR_STRING GatewayList;
' IP_ADDR_STRING DhcpServer;
' BOOL HaveWins;
' IP_ADDR_STRING PrimaryWinsServer;
' IP_ADDR_STRING SecondaryWinsServer;
' time_t LeaseObtained;
' time_t LeaseExpires;
'}

'declared as structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure IPAdapterInfo

Public NextPointer As IntPtr
Public ComboIndex As Integer

<MarshalAs(UnmanagedType.ByValTStr, _
SizeConst:=IPConfigConst.MAX_ADAPTER_NAME_LENGTH + 4)> _
Public AdapterName As String

<MarshalAs(UnmanagedType.ByValTStr, _
SizeConst:=IPConfigConst.MAX_ADAPTER_DESCRIPTION_LENGTH + 4)> _
Public Description As String

Public AddressLength As Integer

<MarshalAs(UnmanagedType.ByValArray, _
SizeConst:=IPConfigConst.MAX_ADAPTER_ADDRESS_LENGTH)> _
Public Address() As Byte

Public Index As Integer
Public Type As Integer
Public DhcpEnabled As Integer
Public CurrentIPAddress As IntPtr
Public IPAddressList As IPAddrString
Public GatewayList As IPAddrString
Public DhcpServer As IPAddrString
Public HaveWins As Boolean
Public PrimaryWinsServer As IPAddrString
Public SecondaryWinsServer As IPAddrString
Public LeaseObtained As Integer
Public LeaseExpires As Integer
End Structure


'typedef struct _IP_ADDR_STRING
'{
' struct _IP_ADDR_STRING* Next;
' IP_ADDRESS_STRING IpAddress;
' IP_MASK_STRING IpMask;
' DWORD Context;
'}

'declared as structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure IPAddrString

Public NextPointer As IntPtr

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=4 * 4)> _
Public IPAddressString As String

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=4 * 4)> _
Public IPMaskString As String

Public Context As Integer
End Structure


'typedef struct _IP_ADAPTER_INDEX_MAP
'{
' ULONG Index // adapter index
' WCHAR Name [MAX_ADAPTER_NAME]; // name of the adapter
'}

'declared as structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Public Structure IPAdapterIndexMap

Public Index As Integer

<MarshalAs(UnmanagedType.ByValTStr, _
SizeConst:=IPConfigConst.MAX_ADAPTER_NAME)> _
Public Name As String
End Structure


'typedef struct _IP_INTERFACE_INFO
'{
' LONG NumAdapters; // number of adapters in array
' IP_ADAPTER_INDEX_MAP Adapter[1]; // adapter indices and names
'}

'declared as structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Public Structure IPInterfaceInfo

Public NumAdapters As Integer
Public Adapter As IPAdapterIndexMap
End Structure

'typedef struct
'{
' char HostName[MAX_HOSTNAME_LEN + 4] ;
' char DomainName[MAX_DOMAIN_NAME_LEN + 4];
' PIP_ADDR_STRING CurrentDnsServer;
' IP_ADDR_STRING DnsServerList;
' UINT NodeType;
' char ScopeId[MAX_SCOPE_ID_LEN + 4];
' UINT EnableRouting;
' UINT EnableProxy;
' UINT EnableDns;
'}

'declared as class

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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