PDA

View Full Version : Hosts File Tool



VB
07-29-2003, 01:18 PM
A small command line tool for adding/removing the supertrick to an existing hosts file.

Command line:

hoststool add example.txt

This will parse the entries in the file example.txt and add them to the hosts file. But only those that are not yet present in the hosts file.

It should mark the added entries like this:



(existing entries)

# BEGIN of Kazaa Lite K++ Supertrick
(added entries go here)
# END of Kazaa Lite K++ Supertrick


If there already is such a block of entries present in the hosts files then it should either insert new entries inside that block, or create a second block. Programmers decision.

hoststool remove

This will remove the whole block (or blocks) that where created as shown above.

Before it does this it should prompt (preferably with a GUI) to ask if the supertrick should really be removed or not. When an extra parameter is used (/s) then it should skip the prompt.

hoststool removeall

This will empty the whole hosts file and only add one line:
127.0.0.1 localhost

secfan
07-29-2003, 02:03 PM
How about using a program such as Hostess??? http://accs-net.com/hostess/

VB
07-29-2003, 02:43 PM
That's too big.

aldo
07-29-2003, 04:45 PM
Try this one:
http://www.aldostools.com/temp/updatehosts.zip

If you pass a HOSTS file as command line parameter, it auto-update the current HOSTS file.

The HOSTS are saved in sorted order.

___
Aldo Vargas
http://www.aldostools.com

VB
07-29-2003, 05:44 PM
I will have a look at it. It's better as what I do know with the hosts file.


I don't think many people will like that it is in sorted order. That way you can't see what was added last.

Also it has no uninstallation option (yet).

aldo
07-29-2003, 07:13 PM
I have updated the program, now the HOSTS are not sorted. The new additions are listed in the small listbox at the right of the window.

Also I have fixed a problem with the listbox from Visual Basic 5 when the list contains over 32767 items. Now the Listbox is managed using APIs.

Download the updated version from the same URL.

It doesn't require unistallation, due it doesn't write to the registry or install any dll. It only uses standard DLLs from Win32 API.

___
Aldo Vargas
http://www.aldostools.com

Elistas5959
07-30-2003, 02:11 AM
I think what he means is that there's no option to remove the IP addresses that were added to the Host file. Because he want's the SuperTrick to be able to be "uninstalled" using this tool. It just needs a routine that removes all text between the lines:

# BEGIN of Kazaa Lite K++ Supertrick

# END of Kazaa Lite K++ Supertrick

or whatever you've made it.

Barbarossa
07-30-2003, 11:56 AM
Hosts file update tools are a pain, because MicroShaft decided to change the location of the hosts file in different releases of Windows.

In 95, 98, ME it's in "C:\Windows\"

In XP, it's in "C:\Windows\system32\drivers\etc\"

I dunno where it is on NT or 2000.. Anyway, I'm sure Aldo has taken all this into account ;)

Livy
07-30-2003, 11:58 AM
in nt and 2000 its in the same place as xp, or the proper way would be in xp its in the same place as 2000, but this is the same for other things aswell, as they are different os's for diff things,

Amarjit
07-30-2003, 12:10 PM
I can do this, I did a similar thing with XML and importing/exporting them into TEXT files.

Easy, here's what'd it look like in C++:


#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()

{

string supertrick;

ifstream example("example.txt");
if ( ! example )
{
cout << "Error opening example file." << endl;
return -1;
}

ofstream hosts("hosts.txt", ios::app);
if ( ! hosts )
{
cout << "Error opening example file." << endl;
return -1;
}

while ( ! example.eof() )
{
getline(example, supertrick);
hosts << example << endl;

}

hosts.close();
example.close();

return 0;

}

I think I uninstalled the GNU C++ Compiler, so someone will have to test this application out and debug it.

In the Command Prompt use the following line to compile:


C++ example.cpp -o example.exe
And then simply run:

example.exe

All in red, obviously needs to be changed accordingly.

aldo
07-30-2003, 02:24 PM
@Paul,
I have updated my HOSTS tool, now supports the command lines:
/add "fullpath" = merge a new hosts file with an existing one
/remove [/s] "section name" = remove all the sections that begin with the specified name
/removeall [/s] = clear the HOSTS file

/s = silence mode

Download:
http://www.aldostools.com/temp/updatehosts.zip

Notes:
- The new HOSTS file should include the comments at the begining and at the end of the file.
- The /remove will add the prefix "#BEGIN of " and "#END of" if the "section name" does not start with #. If the "section name" start with #, the prefix is not used and the "section name" is used instead.

Example:
#BEGIN of KL Supertrick 7/30/2003
127.0.0.1 server1
127.0.0.1 server2
#END of KL Supertrick

#BEGIN of KL Supertrick 8/31/2003
127.0.0.1 server3
127.0.0.1 server4
#END of KL Supertrick

#KL Sites
127.0.0.1 server5
127.0.0.1 server6
#

#KL
127.0.0.1 server7
127.0.0.1 server8
#

/remove "KL Supertick" removes the blocks with servers 1,2,3,4.
/remove "KL Supertick 8/31/2003" removes the blocks with servers 3,4.
/remove "#KL" removes the blocks with servers 5,6,7,8
/remove "#KL Sites" removes the blocks with server 5,6

___
Aldo Vargas
http://www.aldostools.com

VB
07-30-2003, 05:04 PM
Great work Aldo!

Seems to work like a charm B)



I found a small bug:

When you add a new host file that contains new entries in a section with the same name as a section that already exists in the hosts file, then it will add the new entries to the hosts file, but without a section around it.

VB
07-30-2003, 05:47 PM
/removeall doesn't seem to work

aldo
07-30-2003, 07:47 PM
I updated the tool. Same url.

New:
- Fixed the /removeall bug. The code was misplaced :)
- The comments are not verified by the duplicates filter
- New command line: /noload (do not load the HOSTS file, to open the program faster)


___
Aldo Vargas
http://www.aldostools.com

VB
07-30-2003, 09:36 PM
Works great now.

secfan
07-31-2003, 07:24 AM
And don't forget Auto-Update/Auto-Run before startup of KLK++ options or something similar for Hosts Updater. (Maybe merging both Hosts/Bad IP Ranges Updaters together into one??? And include both in KLK++ 2.42!!! ;) )

DarkBlizzard
07-31-2003, 07:28 AM
Originally posted by secfan@31 July 2003 - 02:24
And don't forget Auto-Update/Auto-Run before startup of KLK++ options or something similar for Hosts Updater. (Maybe merging both Hosts/Bad IP Ranges Updaters together into one??? And include both in KLK++ 2.42!!! ;) )
This shouldn't be done because the Hosts file isnt like Peer Guardian....its not like it gets updates every 2 seconds...it rarely gets them. Its sort of pointless.

Here's my little Hosts file site...( Mine and Kazaa Lite's hardly ever get updated , unless someone tells me of a pop-up they got)

http://www.Geocities.com/Klitehostsfile

Sarkie_2002
07-31-2003, 08:26 AM
ive have some Big Ass Hosts file on my Site, which i used to update all the time, but i dunt anymore, if anyones interested

aldo
07-31-2003, 04:09 PM
I have updated the UpdateHOSTS.exe

- Faster HOSTS merge from the GUI
- Changed the "Finding Duplicates" message to "Loading HOSTS...", to make the KL installer activity more clear.
- Fixed the click event on the new hosts list when the main list has more than 32767 items.

Donwload: http://www.aldostools.com/hosts.html
___
Aldo Vargas
http://www.aldostools.com

RealitY
07-31-2003, 11:48 PM
Nice.

DarkBlizzard
08-01-2003, 12:11 AM
Ok, well i change my mind....its a very good idea... :) ..it seems like there's alot of people with different hosts file so would should all combind them :)

VB
08-02-2003, 11:34 AM
@ Aldo


Make your tool detect the Windows version.

NT based: %windir%\system32\drivers\etc\hosts
9x: %windir%\hosts


If the hosts file doesn't exist, then create it.

aldo
08-02-2003, 05:07 PM
Please try the new version.
http://aldostools.mysite4now.com/hosts.html

___
Aldo Vargas
http://www.aldostools.com

VB
08-03-2003, 03:32 PM
Suggestions:

- Add a button to clear the hosts file.
- Add a button to edit the hosts file. This should open up the hosts file in Notepad.exe

aldo
08-03-2003, 05:34 PM
What's new in version 1.3:
- Fixed bug in the confirm dialog
- New Open and Clear buttons
- If you right click on the HOSTS labels will open the folder
- Additional improvements


Download: http://aldostools.mysite4now.com/hosts.html

___
Aldo Vargas
http://www.aldostools.com