Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Combination Ping, NSLOOKUP and echo from txt file script  (Read 15883 times)

0 Members and 1 Guest are viewing this topic.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: Combination Ping, NSLOOKUP and echo from txt file script
« Reply #15 on: August 06, 2014, 06:16:58 AM »
Use this instead.

Code: [Select]
findstr /i /c:"%~1" "home.txt" >>"file.log"

MadFly

    Topic Starter


    Rookie
    • Experience: Familiar
    • OS: Windows 7
    Re: Combination Ping, NSLOOKUP and echo from txt file script
    « Reply #16 on: August 06, 2014, 11:40:35 PM »
    for some reason that still returns nothing and file.log is empty.
    the closest to working that i had so far was...

    Code: [Select]
    :: Get Location of machine
    :: replace tokens=3 with delims= to get the whole line
    for /f "usebackq tokens=3" %%a in ("home.txt") do (
       echo "%%a"
    )

    however, this echos out everything in home.txt. and not only the location of specified IP or ONLY the line where the IP address is found.

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: Combination Ping, NSLOOKUP and echo from txt file script
    « Reply #17 on: August 07, 2014, 07:51:39 AM »
    Only you know what is in the home.txt file and in the %~1 term. 

    Run this yourself to prove that it works.

    Code: [Select]
    @echo off
    echo Computer1 - basement>home.txt
    echo Computer2 - treehouse>>home.txt
    findstr /i /c:"Computer1" "home.txt" >>"file.log"

    MadFly

      Topic Starter


      Rookie
      • Experience: Familiar
      • OS: Windows 7
      Re: Combination Ping, NSLOOKUP and echo from txt file script
      « Reply #18 on: August 07, 2014, 10:22:30 AM »
      ok, don't know what i did wrong or where it went wrong...
      commented every step, echo'd what is happening.
      cls the screen after each step and explaining the next step...

      now it works like a charm again, and tells me only the IP and location of the hostname i originally searched for.

      is there and way to only show the treehouse part after the Computer1 -

      i have removed the >> file.log and now it echos out onscreen :)

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: Combination Ping, NSLOOKUP and echo from txt file script
      « Reply #19 on: August 07, 2014, 10:42:36 AM »
      Given this home.txt

      Code: [Select]
      172.16.4.15 - Reception
      172.16.5.155 - Server Room

      then this should work.

      Code: [Select]
      for /f "tokens=1,* delims=- " %%a in ('findstr /i /c:"%~1" "home.txt" ') do echo %%b

      As mentioned in an earlier post, if your network is IPV6 capable then the ping test can fail and skip servers.
      « Last Edit: August 07, 2014, 11:02:23 AM by foxidrive »

      MadFly

        Topic Starter


        Rookie
        • Experience: Familiar
        • OS: Windows 7
        Re: Combination Ping, NSLOOKUP and echo from txt file script
        « Reply #20 on: August 07, 2014, 10:56:55 AM »
        nah its fine. its really fine if it echos out the ip as well as the - server room part from home.txt
        when changed to your latest suggestion it again echos out nothing.

        i believe very strongly that the network is not ipv6 enabled. however, ipv6 dhcp seems to be working.
        but everything and all systems still work on the ipv4 addresses.

        thanks again.

        i am happy with
        Code: [Select]
        findstr /i /c:"%IPAddress%" "home.txt"

        foxidrive



          Specialist
        • Thanked: 268
        • Experience: Experienced
        • OS: Windows 8
        Re: Combination Ping, NSLOOKUP and echo from txt file script
        « Reply #21 on: August 07, 2014, 11:04:28 AM »
        Use this as home.txt which is what you said the format of the file was:

        Code: [Select]
        172.16.4.15 - Reception
        172.16.5.155 - Server Room

        and run this as: myfile.bat 172.16.4.15 to prove to yourself that it works.  I did change the last %%a to %%b

        Code: [Select]
        @echo off
        for /f "tokens=1,* delims=- " %%a in ('findstr /i /c:"%~1" "home.txt" ') do echo %%b
        pause


        MadFly

          Topic Starter


          Rookie
          • Experience: Familiar
          • OS: Windows 7
          Re: Combination Ping, NSLOOKUP and echo from txt file script
          « Reply #22 on: August 07, 2014, 12:09:06 PM »
          if i could...
          i would give you a medal  8)
          Working as hoped it should work.

          just had to add the
          Code: [Select]
          %IPAddress% variable in the findstr line to allow it to follow the rest of the script.
          Code: [Select]
          for /f "tokens=1,* delims=- " %%a in ('findstr /i /c:"%IPAddress%" "home.txt" ') do echo %%bthank you.