Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Get IP address for a remote computer based on its hostname

I'd like to get, with VBA, the IP address(es) if a computer based on its
hostname :

eg. Cell "a1" = PCXXX
Cell "a2" = XX.XX.XX.XX

I have seen some example that put the result of a ping into a text file,
then pars this text file and put in cells the ip address into a cell.

Is there another way ? I'm using Excel 2003
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Get IP address for a remote computer based on its hostname

Hi
try:
'----------------------------------------
Sub test()
Dim v As Variant
Dim Filename As String, f As String
Dim ip As String

Filename = "E:\iptemp"
'Create command file
f = CreateCommandFile(Filename, "www.yahoo.com")
'run the command in silent mode
Shell f, vbHide
'get info from output file
v = GetIpInfo(Filename & ".txt")
MsgBox v

'add code here to delete files
End Sub

'Creates a .bat file containing ping. Output into file FileName & ".txt"
Function CreateCommandFile(Filename As String, ip As String)
Dim n As Long, File As String, s As String

File = Filename & ".bat"
s = "ping " & ip & " " & Filename & ".txt"
n = FreeFile()

Open File For Output Access Write As #n
Print #n, s
Close #n

CreateCommandFile = File
End Function

'Get ip info
' need to add code in case of no reply during the ping
Function GetIpInfo(Filename As String)
Dim n As Long, s As String

n = FreeFile()
Open Filename For Input Access Read As #n
Line Input #n, s
Line Input #n, s
Line Input #n, s 'data on third row
Close #n

'extract info within the 2 brackets [ ] of text file
n = Strings.InStr(s, "[")
s = Strings.Right(s, Len(s) - n)
n = Strings.InStr(s, "]")
s = Strings.Left(s, n - 1)

GetIpInfo = s
End Function
'---------------------------------------------------------
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"stabilo" wrote:

I'd like to get, with VBA, the IP address(es) if a computer based on its
hostname :

eg. Cell "a1" = PCXXX
Cell "a2" = XX.XX.XX.XX

I have seen some example that put the result of a ping into a text file,
then pars this text file and put in cells the ip address into a cell.

Is there another way ? I'm using Excel 2003

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hostname from IP address NickT Excel Worksheet Functions 1 April 9th 10 02:31 PM
Accessing Remote MDB Database from Local Computer [email protected] Excel Programming 1 February 9th 06 08:11 PM
running excel macros on remote computer TxRaistlin Excel Programming 0 September 10th 05 07:28 AM
Excel /vba / computer IP address jolipe Excel Programming 1 June 3rd 05 07:50 PM
Calling a macro on a remote computer Maury Markowitz Excel Programming 0 February 10th 05 06:21 PM


All times are GMT +1. The time now is 04:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"