+ Post New Thread
Page 3 of 3 FirstFirst 123
Results 31 to 36 of 36
General Chat Thread, Progam/Scripting Challenge - where am I in General; if you used that vbscript into a html page because you have the strComputer ="." would that get the ip ...
  1. #31

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,754
    Thank Post
    3,265
    Thanked 1,052 Times in 973 Posts
    Rep Power
    365
    if you used that vbscript into a html page because you have the strComputer ="." would that get the ip address of the computer it was ran on or what exactly ?

  2. #32
    sahmeepee's Avatar
    Join Date
    Oct 2005
    Location
    Greater Manchester
    Posts
    795
    Thank Post
    20
    Thanked 70 Times in 42 Posts
    Rep Power
    33
    If you want a DOS version to pick out the first 10.x.yy.zzz line, how's this?

    save this as ip.bat then run it. THe commands won't run properly directly from the commandline because of a weirdness around %%s

    Code:
    @echo off
    ipconfig | findstr "10.[0-9]" | findstr "Address" > ip.txt
    for /F "usebackq tokens=15* delims= " %%a in (ip.txt) do echo %%a
    del ip.txt
    Last edited by sahmeepee; 6th March 2009 at 04:34 PM. Reason: it's important to be tidy ;)

  3. Thanks to sahmeepee from:

    SimpleSi (7th March 2009)

  4. #33

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,754
    Thank Post
    3,265
    Thanked 1,052 Times in 973 Posts
    Rep Power
    365
    Quote Originally Posted by sahmeepee View Post
    If you want a DOS version to pick out the first 10.x.yy.zzz line, how's this?

    save this as ip.bat then run it. THe commands won't run properly directly from the commandline because of a weirdness around %%s

    Code:
    @echo off
    ipconfig | findstr "10.[0-9]" | findstr "Address" > ip.txt
    for /F "usebackq tokens=15* delims= " %%a in (ip.txt) do echo %%a
    del ip.txt
    I can't do all the whiz bang stuff in a bat file as per above lol - Im more used to vbs and more modern languages.

  5. #34
    sahmeepee's Avatar
    Join Date
    Oct 2005
    Location
    Greater Manchester
    Posts
    795
    Thank Post
    20
    Thanked 70 Times in 42 Posts
    Rep Power
    33
    Obviously instead of just doing an echo it could do: wget http://yourhost.sch.uk/mapMe.php?ip=%%a

    No pootling about required!

  6. #35

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    11,139
    Thank Post
    860
    Thanked 2,692 Times in 2,282 Posts
    Blog Entries
    9
    Rep Power
    771
    Not need to resort to DOS

    This way gets rid of one textfile all together and does it all (other than the actual FTPing) in VBS

    Code:
    WriteLocationFile "c:\ipaddress.txt",GetLocalIP 
    SendViaFTP
    DeleteLocationFile "c:\ipaddress.txt"
    
    Sub WriteLocationFile(sFilePath, sText)
        Dim objFSO 'As FileSystemObject
        Dim objTextFile 'As Object
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objTextFile = objFSO.CreateTextFile(sFilePath, True)
        objTextFile.Write (sText)	' Write a line.
        objTextFile.Close
    End Sub
    
    Sub SendViaFTP()
        Dim WSHShell
        Set WSHShell = WScript.CreateObject("WScript.Shell")
        WSHShell.Run "ftp", 1, false ' open normal window and do not wait
        Wscript.Sleep 200		'sleep for 0.2 of a second
        WSHShell.SendKeys "open www.*********.sch.uk" & VbCrLf
        Wscript.Sleep 1000		'sleep for 0.2 of a second
        WSHShell.SendKeys "User *********" & VbCrLf
        Wscript.Sleep 200		'sleep for 0.2 of a second
        WSHShell.SendKeys "********" & VbCrLf
        Wscript.Sleep 200		'sleep for 0.2 of a second
        WSHShell.SendKeys "bin" & VbCrLf
        Wscript.Sleep 200		'sleep for 0.2 of a second
        WSHShell.SendKeys "put c:\ipaddress.txt" & VbCrLf
        Wscript.Sleep 200		'sleep for 0.2 of a second
        WSHShell.SendKeys "quit" & VbCrLf
        Set WSHShell = Nothing
    End Sub
    
    Sub DeleteLocationFile(strFilePath)
        set objFSO = CreateObject("Scripting.FileSystemObject")
        objFSO.DeleteFile(strFilePath)
    End Sub
    
    Function GetLocalIP
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
        Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
        For Each objItem in colItems
            For Each strAddress in objItem.IPAddress
    	    if left(strAddress,3) = "10." then
                    GetLocalIP = strAddress
                end if
            Next
        Next
    End Function
    Not sure about the " WSHShell.SendKeys "User *********" & VbCrLf" line as now that it is not connecting inline you may just need to provide the username without the prefix. The sleep intervals could also be cut down lots, i just left them long to see what was going on, I would leave a gap of 1.5 seconds for it to actually connect though depending on how quick your FTP server is.
    Last edited by SYNACK; 7th March 2009 at 06:33 AM.

  7. Thanks to SYNACK from:

    SimpleSi (7th March 2009)

  8. #36
    sahmeepee's Avatar
    Join Date
    Oct 2005
    Location
    Greater Manchester
    Posts
    795
    Thank Post
    20
    Thanked 70 Times in 42 Posts
    Rep Power
    33
    I can see how that is much more elegant (ahem!) So without resorting to 12 pages of VBscript ...

    Code:
    @echo off
    REM Take down your particulars:
    set IPUpdaterHostname=www.yourschool.sch.uk
    set IPUpdaterUsername=yourFTPUsername
    set IPUpdaterPassword=yourFTPPassword(Leave blank to be prompted)
    
    REM Extracting the IP address:
    ipconfig | findstr "10.[0-9]" | findstr "Address" > ip.txt
    for /F "tokens=15 delims= " %%a in (ip.txt) do echo %%a>ip.txt
    
    REM Uploading the IP address:
    if not defined IPUpdaterPassword set /p IPUpdaterPassword=Enter your password: 
    echo open %IPUpdaterHostname% > IPUpdaterFTP.txt
    echo %IPUpdaterUsername% >> IPUpdaterFTP.txt
    echo %IPUpdaterPassword% >> IPUpdaterFTP.txt
    echo put ip.txt >> IPUpdaterFTP.txt
    echo quit >> IPUpdaterFTP.txt
    ftp -s:IPUpdaterFTP.txt
    
    REM Tidying up:
    del ip.txt && del IPUpdaterFTP.txt
    set IPUpdaterHostname=&&set IPUpdaterUsername=&&set IPUpdaterPassword=
    If you want to hard-code the settings into the script you can trim those 4 lines near the top of course

    It's only a couple more lines to add a text file lookup so it would upload your location instead of your IP address.
    Last edited by sahmeepee; 7th March 2009 at 01:27 PM.

  9. Thanks to sahmeepee from:

    SimpleSi (7th March 2009)

SHARE:
+ Post New Thread
Page 3 of 3 FirstFirst 123

Similar Threads

  1. Anyone care for a challenge
    By contink in forum Hardware
    Replies: 0
    Last Post: 25th January 2008, 01:53 PM
  2. Replies: 10
    Last Post: 14th September 2007, 07:59 PM
  3. A Challenge
    By sqdge in forum How do you do....it?
    Replies: 7
    Last Post: 6th August 2007, 11:35 AM
  4. A challenge!
    By Halfmad in forum General Chat
    Replies: 12
    Last Post: 31st July 2007, 01:40 PM
  5. Challenge
    By SteveT in forum General Chat
    Replies: 12
    Last Post: 30th April 2006, 08:27 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •