chleuh
Messages postés5Date d'inscriptionlundi 3 mars 2003StatutMembreDernière intervention 9 juillet 2005
-
22 juin 2005 à 15:10
daetips
Messages postés142Date d'inscriptionjeudi 10 juillet 2003StatutMembreDernière intervention10 novembre 2007
-
22 juin 2005 à 15:30
Bonjour je souhaite savoir comment on fait pour récuperer l'adresse IP
de mon serveur dns primaire et secondaire l'ip de la passerele et du
masque de sous reseau
daetips
Messages postés142Date d'inscriptionjeudi 10 juillet 2003StatutMembreDernière intervention10 novembre 2007 22 juin 2005 à 15:30
Tien ca viens du site, ta une form 2 labels(label5 et label6 avec autosize=true):
'''''''''''''''''''''''''
'Dans un module
Private Const MAX_HOSTNAME_LEN = 128
Private Const MAX_DOMAIN_NAME_LEN = 128
Private Const MAX_SCOPE_ID_LEN = 256
'Private Const ERROR_SUCCESS As Long = 0
Private Type IP_ADDRESS_STRING
IpAddr(0 To 15) As Byte
End Type
Private Type IP_MASK_STRING
IpMask(0 To 15) As Byte
End Type
Private Type IP_ADDR_STRING
dwNext As Long
IpAddress(0 To 15) As Byte
IpMask(0 To 15) As Byte
dwContext As Long
End Type
Private Type FIXED_INFO
HostName(0 To (MAX_HOSTNAME_LEN + 3)) As Byte
DomainName(0 To (MAX_DOMAIN_NAME_LEN + 3)) As Byte
CurrentDnsServer As Long
DnsServerList As IP_ADDR_STRING
NodeType As Long
ScopeId(0 To (MAX_SCOPE_ID_LEN + 3)) As Byte
EnableRouting As Long
EnableProxy As Long
EnableDns As Long
End Type
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Private Declare Function GetNetworkParams Lib "iphlpapi.dll" (pFixedInfo As Any, pOutBufLen As Long) As Long
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'dns
Public Function GetDNSServers(sCurrentDNSServer As String, _
dnssvr() As String) As Long
Dim buff() As Byte
Dim cbRequired As Long
Dim nStructSize As Long
Dim Ptr As Long
Dim fi As FIXED_INFO
Dim ipas As IP_ADDR_STRING
Dim cnt As Long
ReDim dnssvr(0) As String
nStructSize = LenB(ipas)
'call the api first to determine the
'size required for the values to be returned
Call GetNetworkParams(ByVal 0&, cbRequired)
If cbRequired > 0 Then
ReDim buff(0 To cbRequired - 1) As Byte
If GetNetworkParams(buff(0), cbRequired) = ERROR_SUCCESS Then
Ptr = VarPtr(buff(0))
CopyMemory fi, ByVal Ptr, Len(fi)
With fi
'identify the current dns server
CopyMemory ipas, _
ByVal VarPtr(.CurrentDnsServer) + 4, _
nStructSize
'obtain a pointer to the
'DnsServerList array
Ptr = VarPtr(.DnsServerList)
'the IP_ADDR_STRING dwNext member indicates
'that more than one DNS server may be listed,
'so a loop is needed
Do While (Ptr <> 0)
'copy each into an IP_ADDR_STRING type
CopyMemory ipas, ByVal Ptr, nStructSize
With ipas
'extract the server address and
'cast to the array
ReDim Preserve dnssvr(0 To cnt) As String
dnssvr(cnt) = TrimNull(StrConv(ipas.IpAddress, vbUnicode))
Ptr = .dwNext
End With
cnt = cnt + 1
Loop
End With
End If 'If GetNetworkParams
End If 'If cbRequired > 0
'return number of servers found
GetDNSServers = cnt
End Function
Private Function TrimNull(item As String)
Dim pos As Integer
pos = InStr(item, Chr$(0))
If pos Then
TrimNull = Left$(item, pos - 1)
Else: TrimNull = item
End If
End Function
''''''''''''''''''''''''''''''''''''''Dans une form
Private Sub Form_Load()
'dns
' Dim cnt As Long
Dim success As Long
Dim currserver As String
Dim dnsservers() As String
'pass an empty string and string array
'to the function. Return value is the
'number of DNS servers found
success = GetDNSServers(currserver, dnsservers())
'show the current DNS server found
Label5.Caption = "Current DNS Server: " & _
vbNewLine & _
currserver