Computer Hope

Microsoft => Microsoft DOS => Topic started by: plm on April 06, 2009, 06:02:53 AM

Title: batch script Adding Ip adresses to hosts file
Post by: plm 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
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Carbon Dudeoxide on April 06, 2009, 06:08:05 AM
Why do you want to add it to the hosts file?
Title: Re: batch script Adding Ip adresses to hosts file
Post by: BatchFileCommand 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)
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Reno on April 06, 2009, 06:18:20 AM
/removed
Title: Re: batch script Adding Ip adresses to hosts file
Post by: gh0std0g74 on April 06, 2009, 06:25:51 AM
/removed
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Reno on April 06, 2009, 06:30:54 AM
/removed
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Carbon Dudeoxide 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.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: gh0std0g74 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.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Carbon Dudeoxide 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?
Title: Re: batch script Adding Ip adresses to hosts file
Post by: gh0std0g74 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.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Carbon Dudeoxide 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?
Title: Re: batch script Adding Ip adresses to hosts file
Post by: gh0std0g74 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 (http://www.computerhope.com/forum/index.php/topic,80659.0.html)"?  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?
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Reno 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.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Carbon Dudeoxide 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.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Carbon Dudeoxide 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.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Reno 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.

Title: Re: batch script Adding Ip adresses to hosts file
Post by: Carbon Dudeoxide 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......
Title: Re: batch script Adding Ip adresses to hosts file
Post by: gh0std0g74 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.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Carbon Dudeoxide 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...
Title: Re: batch script Adding Ip adresses to hosts file
Post by: gh0std0g74 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.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Carbon Dudeoxide on April 06, 2009, 07:46:21 AM
And if his intentions were bad?  ::)
Title: Re: batch script Adding Ip adresses to hosts file
Post by: gh0std0g74 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?
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Carbon Dudeoxide 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.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Dias de verano 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.

Title: Re: batch script Adding Ip adresses to hosts file
Post by: plm 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
Title: Re: batch script Adding Ip adresses to hosts file
Post by: BC_Programmer 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.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Dias de verano 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?
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Carbon Dudeoxide on April 07, 2009, 05:52:37 AM
You would want software to do this....Not a Hosts file edit....
Title: Re: batch script Adding Ip adresses to hosts file
Post by: gh0std0g74 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?
Title: Re: batch script Adding Ip adresses to hosts file
Post by: gh0std0g74 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.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: gh0std0g74 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 (http://www.netikka.net/tsneti/info/tscmd163.htm) for your reference.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Carbon Dudeoxide on April 07, 2009, 06:47:19 AM
come on, what are talking about?

I am talking about network-administration software.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: Helpmeh 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.
Title: Re: batch script Adding Ip adresses to hosts file
Post by: gh0std0g74 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