"thierry" <tbgfd@club-internet.fr> a écrit dans le message de
news:219201c46ffb$a0ded8d0$a501280a@phx.gbl...
Je désire récupérer l'adresse IP de mon ordinateur pour
effectuer un calcul.
"thierry" a écrit dans le message de news:219201c46ffb$a0ded8d0$ Je désire récupérer l'adresse IP de mon ordinateur pour effectuer un calcul.
Comment faire, simplement.
Merci.
Frédéric Sigonneau
Bonjour,
Deux autres approches possibles (fonctions VBA perso utilisables dans une feuille de calcul ou dans du code) :
'========= si WMI est installé sur le PC (Win 2000 et XP Function AdresseIP() strComputer = "." Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2") Set IPConfigSet = objWMIService.ExecQuery _ ("Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IPConfig In IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress) AdresseIP = IPConfig.IPAddress(i) Next End If Next End Function
'========== sinon, avec le "classique" ipconfig Function MonIP() Dim Commande$, wsh, fso, fich Commande = "command.com /c ipconfig >d:config.txt" Set wsh = CreateObject("WScript.Shell") wsh.Run Commande, 0, True Set fso = CreateObject("Scripting.FileSystemObject") Set fich = fso.OpenTextFile("d:config.txt", 1) MonIP = Split(Trim(Split(fich.readall, ":")(5)), Chr(13))(0) fich.Close Kill "d:config.txt" End Function 'fs
FS --- Frédéric Sigonneau [MVP Excel - né un sans-culottide] Gestions de temps, VBA pour Excel : http://perso.wanadoo.fr/frederic.sigonneau Si votre question sur Excel est urgente, évitez ma bal !
Je désire récupérer l'adresse IP de mon ordinateur pour effectuer un calcul.
Comment faire, simplement.
Merci.
Bonjour,
Deux autres approches possibles (fonctions VBA perso utilisables dans une
feuille de calcul ou dans du code) :
'========= si WMI est installé sur le PC (Win 2000 et XP
Function AdresseIP()
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "rootcimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration where
IPEnabled=TRUE")
For Each IPConfig In IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
AdresseIP = IPConfig.IPAddress(i)
Next
End If
Next
End Function
'========== sinon, avec le "classique" ipconfig
Function MonIP()
Dim Commande$, wsh, fso, fich
Commande = "command.com /c ipconfig >d:config.txt"
Set wsh = CreateObject("WScript.Shell")
wsh.Run Commande, 0, True
Set fso = CreateObject("Scripting.FileSystemObject")
Set fich = fso.OpenTextFile("d:config.txt", 1)
MonIP = Split(Trim(Split(fich.readall, ":")(5)), Chr(13))(0)
fich.Close
Kill "d:config.txt"
End Function 'fs
FS
---
Frédéric Sigonneau [MVP Excel - né un sans-culottide]
Gestions de temps, VBA pour Excel :
http://perso.wanadoo.fr/frederic.sigonneau
Si votre question sur Excel est urgente, évitez ma bal !
Je désire récupérer l'adresse IP de mon ordinateur pour
effectuer un calcul.
Deux autres approches possibles (fonctions VBA perso utilisables dans une feuille de calcul ou dans du code) :
'========= si WMI est installé sur le PC (Win 2000 et XP Function AdresseIP() strComputer = "." Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2") Set IPConfigSet = objWMIService.ExecQuery _ ("Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IPConfig In IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress) AdresseIP = IPConfig.IPAddress(i) Next End If Next End Function
'========== sinon, avec le "classique" ipconfig Function MonIP() Dim Commande$, wsh, fso, fich Commande = "command.com /c ipconfig >d:config.txt" Set wsh = CreateObject("WScript.Shell") wsh.Run Commande, 0, True Set fso = CreateObject("Scripting.FileSystemObject") Set fich = fso.OpenTextFile("d:config.txt", 1) MonIP = Split(Trim(Split(fich.readall, ":")(5)), Chr(13))(0) fich.Close Kill "d:config.txt" End Function 'fs
FS --- Frédéric Sigonneau [MVP Excel - né un sans-culottide] Gestions de temps, VBA pour Excel : http://perso.wanadoo.fr/frederic.sigonneau Si votre question sur Excel est urgente, évitez ma bal !
Je désire récupérer l'adresse IP de mon ordinateur pour effectuer un calcul.
Comment faire, simplement.
Merci.
Misange
c'est ici : http://www.excelabo.net/xl/application.php#adresseIP :-) Misange migrateuse http://www.excelabo.net mail : http://cerbermail.com/?k5Q8Dh2mta
le 22/07/2004 16:53:
Je désire récupérer l'adresse IP de mon ordinateur pour effectuer un calcul.
Comment faire, simplement.
Merci.
c'est ici :
http://www.excelabo.net/xl/application.php#adresseIP
:-)
Misange migrateuse http://www.excelabo.net
mail : http://cerbermail.com/?k5Q8Dh2mta
le 22/07/2004 16:53:
Je désire récupérer l'adresse IP de mon ordinateur pour
effectuer un calcul.