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

Author Topic: batch script Adding Ip adresses to hosts file  (Read 13758 times)

0 Members and 1 Guest are viewing this topic.

plm

    Topic Starter


    Newbie

    batch script Adding Ip adresses to hosts file
    « on: April 06, 2009, 06:02:53 AM »
    Hi Computerhope

    I am trying to make a batch script that takes the list of Ip adresses from A.txt and appends it to B.txt with the following command:

    type B.txt>>A.txt

    content of A.txt:
    10.20.30.40
    50.60.70.80

    content of B.txt
    1.2.3.4
    5.6.7.8

    But how do i make sure that the ip adresses from B.txt are being inserted in the bottom of the A.txt file (makes a new line). My A.txt ends up looking like this:

    10.20.30.40
    50.60.70.801.2.3.4
    5.6.7.8

    Bets regards plm

    Carbon Dudeoxide

    • Global Moderator

    • Mastermind
    • Thanked: 169
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Experience: Guru
    • OS: Mac OS
    Re: batch script Adding Ip adresses to hosts file
    « Reply #1 on: April 06, 2009, 06:08:05 AM »
    Why do you want to add it to the hosts file?

    BatchFileCommand



      Hopeful
    • Thanked: 1
      Re: batch script Adding Ip adresses to hosts file
      « Reply #2 on: April 06, 2009, 06:15:59 AM »
      Oh goodie  ;D, with a file of IP Addresses you could use those to chat in school (trust me, I know how it's done)
      οτη άβγαλτος μεταφ βαθμολογία

      Reno



        Hopeful
      • Thanked: 32
        Re: batch script Adding Ip adresses to hosts file
        « Reply #3 on: April 06, 2009, 06:18:20 AM »
        /removed
        « Last Edit: April 06, 2009, 06:55:33 AM by Carbon Dudeoxide »

        gh0std0g74



          Apprentice

          Thanked: 37
          Re: batch script Adding Ip adresses to hosts file
          « Reply #4 on: April 06, 2009, 06:25:51 AM »
          /removed
          « Last Edit: April 06, 2009, 06:55:30 AM by Carbon Dudeoxide »

          Reno



            Hopeful
          • Thanked: 32
            Re: batch script Adding Ip adresses to hosts file
            « Reply #5 on: April 06, 2009, 06:30:54 AM »
            /removed
            « Last Edit: April 06, 2009, 06:55:24 AM by Carbon Dudeoxide »

            Carbon Dudeoxide

            • Global Moderator

            • Mastermind
            • Thanked: 169
              • Yes
              • Yes
              • Yes
            • Certifications: List
            • Experience: Guru
            • OS: Mac OS
            Re: batch script Adding Ip adresses to hosts file
            « Reply #6 on: April 06, 2009, 06:55:56 AM »
            Sorry guys, I removed your suggestion.  I would like to know why Plm needs to do this.

            gh0std0g74



              Apprentice

              Thanked: 37
              Re: batch script Adding Ip adresses to hosts file
              « Reply #7 on: April 06, 2009, 07:12:09 AM »
                I would like to know why Plm needs to do this.
              i would like to know why you removed them.

              Carbon Dudeoxide

              • Global Moderator

              • Mastermind
              • Thanked: 169
                • Yes
                • Yes
                • Yes
              • Certifications: List
              • Experience: Guru
              • OS: Mac OS
              Re: batch script Adding Ip adresses to hosts file
              « Reply #8 on: April 06, 2009, 07:13:11 AM »
              You want him, and the entire world, to know how to add IP address into the Hosts file?
              Do you know what that could do?

              gh0std0g74



                Apprentice

                Thanked: 37
                Re: batch script Adding Ip adresses to hosts file
                « Reply #9 on: April 06, 2009, 07:16:50 AM »
                You want him, and the entire world, to know how to add IP address into the Hosts file?
                Do you know what that could do?
                aren't you being too sensitive? he asked a legit question on how to append to files properly. Adding ip address to hosts files is just common practice anyway among system administrators. Until proven guilty, everyone is innocent.

                Carbon Dudeoxide

                • Global Moderator

                • Mastermind
                • Thanked: 169
                  • Yes
                  • Yes
                  • Yes
                • Certifications: List
                • Experience: Guru
                • OS: Mac OS
                Re: batch script Adding Ip adresses to hosts file
                « Reply #10 on: April 06, 2009, 07:18:35 AM »
                Quote
                Re: batch script Adding Ip adresses to hosts file
                Nice title.

                Anyways, this is a public forum. anyone can view the information posted here. Perfect for pranksters, eh?

                gh0std0g74



                  Apprentice

                  Thanked: 37
                  Re: batch script Adding Ip adresses to hosts file
                  « Reply #11 on: April 06, 2009, 07:23:40 AM »
                  Nice title.
                  so ?
                  Quote
                  Anyways, this is a public forum. anyone can view the information posted here. Perfect for pranksters, eh?
                  wow, why don't you remove the suggestions from the thread that that says "how to read target from shortcut"?  Do you know what would happen if a prankster changes something in that shortcut that tries to delete an important file(for example) if double clicked?

                  Reno



                    Hopeful
                  • Thanked: 32
                    Re: batch script Adding Ip adresses to hosts file
                    « Reply #12 on: April 06, 2009, 07:30:29 AM »
                    Sorry guys, I removed your suggestion.  I would like to know why Plm needs to do this.
                    no problem, i don't know if hosts file should not be edited.

                    Carbon Dudeoxide

                    • Global Moderator

                    • Mastermind
                    • Thanked: 169
                      • Yes
                      • Yes
                      • Yes
                    • Certifications: List
                    • Experience: Guru
                    • OS: Mac OS
                    Re: batch script Adding Ip adresses to hosts file
                    « Reply #13 on: April 06, 2009, 07:30:34 AM »
                    No point in arguing.

                    I have had hands-on experiencing regarding Hosts file edits. A friend created a batch file that redirected popular URLs to a website I need not mention here. He ran this batch file on several of the laptops in my class and caused a great deal of trouble in the lesson.
                    None of them knew how to undo this. They didn't know where the problem lay, nor did they know what the Hosts file was.

                    I asked Plm 'why he wanted to do this', and BatchFileCommand concurred with my assessment.
                    You went ahead and posted the potentially harmful information anyways.

                    Read the forum rules under Causing users grief / hacking.

                    You should be glad I didn't simply delete your posts and offer no reason why I did it.

                    Carbon Dudeoxide

                    • Global Moderator

                    • Mastermind
                    • Thanked: 169
                      • Yes
                      • Yes
                      • Yes
                    • Certifications: List
                    • Experience: Guru
                    • OS: Mac OS
                    Re: batch script Adding Ip adresses to hosts file
                    « Reply #14 on: April 06, 2009, 07:33:03 AM »
                    no problem, i don't know if hosts file should not be edited.

                    This Hosts file can be edited. It is edited in some situations. But take note that many viruses modify the Hosts file just to cause trouble. Large networks have special programs to monitor network traffic and block sites.

                    Imagine trying to get to www.google.com but being transferred to a site to buy a fake antivirus that steals sensitive information from your computer.

                    Reno



                      Hopeful
                    • Thanked: 32
                      Re: batch script Adding Ip adresses to hosts file
                      « Reply #15 on: April 06, 2009, 07:35:57 AM »
                      you are posting some information on how a host file could be "mis-used". could you delete this whole thread?
                      No point in arguing.

                      I have had hands-on experiencing regarding Hosts file edits. A friend created a batch file that redirected popular URLs to a website I need not mention here. He ran this batch file on several of the laptops in my class and caused a great deal of trouble in the lesson.
                      None of them knew how to undo this. They didn't know where the problem lay, nor did they know what the Hosts file was.

                      I asked Plm 'why he wanted to do this', and BatchFileCommand concurred with my assessment.
                      You went ahead and posted the potentially harmful information anyways.

                      Read the forum rules under Causing users grief / hacking.

                      You should be glad I didn't simply delete your posts and offer no reason why I did it.


                      Carbon Dudeoxide

                      • Global Moderator

                      • Mastermind
                      • Thanked: 169
                        • Yes
                        • Yes
                        • Yes
                      • Certifications: List
                      • Experience: Guru
                      • OS: Mac OS
                      Re: batch script Adding Ip adresses to hosts file
                      « Reply #16 on: April 06, 2009, 07:37:54 AM »
                      No, I don't believe this should be deleted. In fact, I just wanted to know what Plm is trying to accomplish, which was my initial question......

                      gh0std0g74



                        Apprentice

                        Thanked: 37
                        Re: batch script Adding Ip adresses to hosts file
                        « Reply #17 on: April 06, 2009, 07:38:53 AM »
                        No point in arguing.

                        I have had hands-on experiencing regarding Hosts file edits. A friend created a batch file that redirected popular URLs to a website I need not mention here. He ran this batch file on several of the laptops in my class and caused a great deal of trouble in the lesson.
                        None of them knew how to undo this. They didn't know where the problem lay, nor did they know what the Hosts file was.

                        I asked Plm 'why he wanted to do this', and BatchFileCommand concurred with my assessment.
                        You went ahead and posted the potentially harmful information anyways.

                        Read the forum rules under Causing users grief / hacking.

                        You should be glad I didn't simply delete your posts and offer no reason why I did it.
                        i definitely DO NOT AGREE with you. He can jolly well edit the host file and type in (or copy and paste) the ip addresses himself, wouldn't he?  you have made a ridiculous assumption, however seeing you as the superior being here, i will rest my case.

                        Carbon Dudeoxide

                        • Global Moderator

                        • Mastermind
                        • Thanked: 169
                          • Yes
                          • Yes
                          • Yes
                        • Certifications: List
                        • Experience: Guru
                        • OS: Mac OS
                        Re: batch script Adding Ip adresses to hosts file
                        « Reply #18 on: April 06, 2009, 07:39:52 AM »
                        Creating the batch file will make it easier for him to use it on other computers, eh?

                        Anyways, this is a hypothetical situation...

                        gh0std0g74



                          Apprentice

                          Thanked: 37
                          Re: batch script Adding Ip adresses to hosts file
                          « Reply #19 on: April 06, 2009, 07:43:33 AM »
                          Creating the batch file will make it easier for him to use it on other computers, eh?

                          Anyways, this is a hypothetical situation...
                          yeah right, the key word is hypothetical. you wouldn't know what he's going to do. maybe he is a legit system admin. therefore, its not right to do what you did.

                          Carbon Dudeoxide

                          • Global Moderator

                          • Mastermind
                          • Thanked: 169
                            • Yes
                            • Yes
                            • Yes
                          • Certifications: List
                          • Experience: Guru
                          • OS: Mac OS
                          Re: batch script Adding Ip adresses to hosts file
                          « Reply #20 on: April 06, 2009, 07:46:21 AM »
                          And if his intentions were bad?  ::)

                          gh0std0g74



                            Apprentice

                            Thanked: 37
                            Re: batch script Adding Ip adresses to hosts file
                            « Reply #21 on: April 06, 2009, 07:52:57 AM »
                            And if his intentions were bad?  ::)
                            how would you know?  so if he were to rephrase his question (or title) without the ip address and host file, but just some example text and file names and ask how to append properly, would you still suspect him of anything?

                            Carbon Dudeoxide

                            • Global Moderator

                            • Mastermind
                            • Thanked: 169
                              • Yes
                              • Yes
                              • Yes
                            • Certifications: List
                            • Experience: Guru
                            • OS: Mac OS
                            Re: batch script Adding Ip adresses to hosts file
                            « Reply #22 on: April 06, 2009, 07:54:51 AM »
                            Not at all, but that avoids my question.

                            No point continuing further. I am ending this now.

                            If you have any other questions or a response, please PM me.

                            Dias de verano

                            • Guest
                            Re: batch script Adding Ip adresses to hosts file
                            « Reply #23 on: April 06, 2009, 09:47:28 AM »
                            An astute sys admin will use file permissions so that limited users cannot alter the Hosts file, and will keep a known good backup.


                            plm

                              Topic Starter


                              Newbie

                              Re: batch script Adding Ip adresses to hosts file
                              « Reply #24 on: April 07, 2009, 04:11:07 AM »
                              Hi CDO

                              I am about to make sure that some hundred monitored servers can send their snmp traps to some newly added monitoring servers during an upgrade. I have no intention of any malicious acts. I am a virgin into scripting so i thought that the experts on batch scripting on this site might be able to get me started.

                              best regards plm

                              BC_Programmer


                                Mastermind
                              • Typing is no substitute for thinking.
                              • Thanked: 1140
                                • Yes
                                • Yes
                                • BC-Programming.com
                              • Certifications: List
                              • Computer: Specs
                              • Experience: Beginner
                              • OS: Windows 11
                              Re: batch script Adding Ip adresses to hosts file
                              « Reply #25 on: April 07, 2009, 05:43:21 AM »
                              the funny thing is if plm had asked how to append data to a text file there would have been no issues.
                              I was trying to dereference Null Pointers before it was cool.

                              Dias de verano

                              • Guest
                              Re: batch script Adding Ip adresses to hosts file
                              « Reply #26 on: April 07, 2009, 05:50:18 AM »
                              Why do people paid to know how to do sys admin come here to find out how to do their jobs?

                              Carbon Dudeoxide

                              • Global Moderator

                              • Mastermind
                              • Thanked: 169
                                • Yes
                                • Yes
                                • Yes
                              • Certifications: List
                              • Experience: Guru
                              • OS: Mac OS
                              Re: batch script Adding Ip adresses to hosts file
                              « Reply #27 on: April 07, 2009, 05:52:37 AM »
                              You would want software to do this....Not a Hosts file edit....

                              gh0std0g74



                                Apprentice

                                Thanked: 37
                                Re: batch script Adding Ip adresses to hosts file
                                « Reply #28 on: April 07, 2009, 06:13:29 AM »
                                You would want software to do this....Not a Hosts file edit....
                                come on, what are talking about?

                                gh0std0g74



                                  Apprentice

                                  Thanked: 37
                                  Re: batch script Adding Ip adresses to hosts file
                                  « Reply #29 on: April 07, 2009, 06:14:30 AM »
                                  the funny thing is if plm had asked how to append data to a text file there would have been no issues.
                                  this is what i said in post #21.

                                  gh0std0g74



                                    Apprentice

                                    Thanked: 37
                                    Re: batch script Adding Ip adresses to hosts file
                                    « Reply #30 on: April 07, 2009, 06:30:47 AM »
                                    Hi CDO

                                    I am about to make sure that some hundred monitored servers can send their snmp traps to some newly added monitoring servers during an upgrade. I have no intention of any malicious acts. I am a virgin into scripting so i thought that the experts on batch scripting on this site might be able to get me started.

                                    best regards plm
                                    since you have spoken , here's a link for your reference.

                                    Carbon Dudeoxide

                                    • Global Moderator

                                    • Mastermind
                                    • Thanked: 169
                                      • Yes
                                      • Yes
                                      • Yes
                                    • Certifications: List
                                    • Experience: Guru
                                    • OS: Mac OS
                                    Re: batch script Adding Ip adresses to hosts file
                                    « Reply #31 on: April 07, 2009, 06:47:19 AM »
                                    come on, what are talking about?

                                    I am talking about network-administration software.

                                    Helpmeh



                                      Guru

                                    • Roar.
                                    • Thanked: 123
                                      • Yes
                                      • Yes
                                    • Computer: Specs
                                    • Experience: Familiar
                                    • OS: Windows 8
                                    Re: batch script Adding Ip adresses to hosts file
                                    « Reply #32 on: April 07, 2009, 07:02:06 PM »
                                    I see this as an excuse to get post-count up.

                                    Carbon said that the code that we could have given could have been used for malicous purposes. It may not be the OP, but like he said, this is a public forum. ANYONE could see/use it.

                                    OP, if you are a sys admin, then you should at least have enough knowledge of computers to make your own easy way to do what you first posted.
                                    Where's MagicSpeed?
                                    Quote from: 'matt'
                                    He's playing a game called IRL. Great graphics, *censored* gameplay.

                                    gh0std0g74



                                      Apprentice

                                      Thanked: 37
                                      Re: batch script Adding Ip adresses to hosts file
                                      « Reply #33 on: April 07, 2009, 07:40:14 PM »
                                      @plm, reply #30 is what you need to get you started. check it out and see if it works for you.
                                      Or, if you have no restriction to download gawk for windows(see my sig)
                                      Code: [Select]
                                      C:\test>gawk "1" file1.txt file2.txt
                                      10.20.30.40
                                      50.60.70.80
                                      1.2.3.4
                                      5.6.7.8