Archive for the ‘Windows’ Category

Unix: Converting files between DOS and Unix

Sunday, February 28th, 2010

Recently I found that, after a uploading file from a Windows computer to a Linux one, and opened the file from the command line, Ubuntu would notify me that it was converting it from the DOS format.

Even if it was a standard text file (.txt) filled with ASCII characters, it still needed converting.

Why? Aren’t text files the same across different operating systems? Evidently not.

Unix handles end-of-line signifiers differently than Windows/DOS does, according to Sumitabha Das’s book “Your Unix”.

Specifically, DOS uses two different sets of characters, “\r” (for Carriage Return [CR], or simply “enter”) and “\n” (for Line Feed [LF]) to signify the end of a line.

Unix only uses one, namely LF

These markers can both be seen by examining text files with Octal Dump.

Ubuntu anyway seems to handle DOS text files easily in day to day operation. Nonetheless, most variants of Unix/Linux have a set of utilities to convert files from Windows/DOS into Unix, and back again. They are called dos2unix and unix2dos, respectively.


Taken from this book:


…as well as a class I’m taking on Unix. All mistakes are my own, however.–Joab Jackson





Windows: Troubleshooting a non-working Hosts file

Saturday, January 30th, 2010

What do you do when your Windows XP computer isn’t recognizing the Hosts file? Here are a few possible solutions.

Recently, I ran into this devil of a problem. I wanted to do some internal testing of a Web site, from a browser on a Windows XP machine. So I added an entry in the hosts file on the XP machine that would redirect joabj.com to the internal IP address of the server (“192.168.0.33 joabj.com” in this case). (Typically, in WinXP, the Hosts file was located in the C:\WINDOWS\system32\drivers\etc folder). Yet, the browser still returned errors!

Yet, the browser kept consulting the external DNS service first, and returning the wrong page (my cable modem page in this case).

Most infuriatingly, Windows host file command line tools (namely, ping and SSH) recognized entries, but the browser did not!! If I ping’ed my domain name entered into the Hosts file (“ping -a joabj.com” in this case), it pinged the correct IP number (“reply from 192.168.0.33:” etc…).

Surfing the Web, I came across a number of different solutions to this problem:

*Reboot: Not only rebooting the machine (duh!), but emptying the browser caches, flushing the DNS (from the command line, type “ipconfig /flushdns”).

*Extra empty characters in the Hosts file: Evidently, Windows doesn’t like an empty space behind the entry, i.e. “192.168.0.33 joabj.com ” rather than “192.168.0.33 joabj.com” –make sure you don’t add in an empty space.

*Corrupt Hosts file: This could be the case even if it opens in Notepad o.k. Try replacing the existing Hosts file with a new one.

*Specify exact subdomain in Hosts file: This is the solution that ultimately worked for me, after trying all these other more complicated solutions, described below.

In a nutshell, if you plan on using the address “www.YOURDOMAIN.com” you should type “www.YOURDOMAIN.com” into the Hosts file, rather than just “YOURDOMAIN.com”.

So, for me, once I replaced “192.168.0.33 joabj.com” with “192.168.0.33 www.joabj.com” then using http://www.joabj.com worked fine, whereas before it wouldn’t.

*Editor adding extension to Hosts file name: Sometimes a text editor could add on the .txt to the file name during save, making it Hosts.txt rather than just Hosts. Of course, then Windows won’t recognize the Hosts file, and Explorer won’t show, by default, the suffixes of file names.

If perusing from Explorer, set the folder view options to show suffixes. From Explorer, go Tools–>Folder Options–>View and uncheck “Hide extensions for known folder types.” If Hosts is a .txt, remove the .txt from the file name.

*XP’s DNS Cache service taking priority: One troubleshooting site suggested this as a probable cause. It didn’t make any difference in my case.

To disable this service, go Start–>Control Panel–>Administrative Tools–>Component Services–>Services(Local). Then search for DNS Cache and disable it. You could just stop the service to check if it has any affect, though it will start up again on reboot. The Manual setting just means that the service will start up, once a browser is fired up. The Disable option turns it off altogether, until you turn it back on again.

According to other people who’ve tried this, disabling DNS Cache should have no ill-effect on your DNSing.

*Reorder the DNS lookup sequence: Typically, Windows XP will consult the local Hosts file before checking with a DNS server to resolve domain name. But, sometimes not.

You change the order of the lookup in the registry. (STANDARD DISCLAIMER: DO not mess w/ registry until you know what you are doing).

To fire up the registry editor, do Start–>Run and put “regedit” in the box.

Once in regedit, go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\ServiceProvider . Once there, you will see a number of entries, including “DnsPriority” “HostsPriority” “LocalPriority” and “NetbtPriority” –which are the entries for DNS-based lookup, Hosts file-based lookup, Computer-based lookup and NetBios-based look-up. (More info on that here).

In the data column for each you see a number in parenthesis. This number is the priority for that lookup. The lower the number, the earlier in the domain name resolution sequence it is consulted (evidently the range is between -32768 and 32767). If the DNS number is lower than the Hosts’ number, then you want to give the Hosts number a lower number than the DNS number.

So if DnsPriority is 5000 and Hosts is 7000, you may want to change Hosts to, say, 4500

Keep in mind, that when you set the number, by right clicking on the entry and choosing “modify,” you just can’t add the number as is — you will have to enter the new number in either hexidecimal or binary.

One easy way to convert a number into hexadecimal is to call up Windows calculator, switch the view from standard to scientific, then enter the number into the field for entering a number. After the number is entered, look for where “dec” is selected on top of the calculator, and switch that to “hex.”

–Joab Jackson





Security: Encrypting Your Files on Windows

Sunday, July 26th, 2009

The following is a description on how to encrypt files on your computer, using only free, open-source software.

Encryption is the act of locking something up so someone else may not view it without a password. This how-to will skip over the implications, technical explanations and history of the technologies being used, for the sake of simplicity.

The basic approach I put in place does this: You have a file you want to encrypt on a Windows computer. So you right-click on the file, and it is encrypted into the new file. When you want to access the file, you unencrypt it, namely by you right-clicking on it again. The program asks for a password. When you supply it, it produces an unencrypted duplicate of the file you encrypted.

Any kind of file can be encrypted in this approach.

In future installments, I’ll delve into how to do this from the Linux command line and how to share encrypted files across multiple computers, as well as sharing encrypted files with others.

* * *

For setting up a free encryption environment in a Windows environment, you’ll need two programs. One does all the behind-the-scenes work of encrypting and decrypting, as well as generating and managing keys. The second program acts as the front-end, which will allow you to apply these tools in an -easy-to-use way.

For the first task, I’ll use a collection of tools called the GNU Privacy Guard (GnuGP). (Here is the How-To). It is an open-source free application and encryption library from the Free Software Foundation. Yay! FSF.

Specifically, I downloaded a version of GnuGP for Windows here. I clicked on the program and it ran me through the installation process. By default it installed all its command-line driven programs (by default) into C:\Program Files\GNU\GnuPG\ folder. If the installer works correctly, all of GnuPG’s functions should be accessible from the command line.

Once this program are in place, you need to generate a key. GnuGP is a form of public key cryptography. A key is a series of digits, used (in this instance) in much the same way a password is

For purpose of this project, all you need to understand is that you need a key for unlocking your files once they are encrypted. To do this, you open the Windows Command Prompt (Go Start–>All Programs–>Accessories–>Command Prompt) and type in “gpg –gen-key” at the command line. Pick the encryption method and run through the other options. For personal encryption, the defaults are a safe bet. I picked DSA, 2048 bits, and a key that does not expire. Follow the instructions attentively.

In this key-generating process, the software asks you for a password. THIS IS THE PASSWORD YOU WILL USE TO UNENCRYPT YOUR FILES. Do not lose or forget this password, or you WILL be unable to access anything you’ve encrypted. That is a fact, Jack. Also, do not put it in a plain-text on the computer where the encrypted files are stored. Duh!

Once you’ve generated a key, you then need to find a program that could work within Microsoft Windows graphical interface that will use this key to encrypt and decrypt a program. Please note though, you could encrypt and decrypt from the command line using GnuPG. A nice graphical program does speed things along though.

The GnuPG site has links to a number of front-ends. For this example I’ll use the free GPGee. Again, download and follow the installation instructions.

You don’t start GPGee like a typical program. Instead, it integrates itself within the Windows Explorer file browser Once installation is complete, all you need to do is open the file browser (Start–>All programs–>Accessories–>Windows Explorer), right-click once on a file. You will see an option for GPGee menu. There you will have an option to encrypt or decrypt a file (either by PK or Symmetric. For this example, we’ll use PK).

Encrypting a file from Windows Explorer.

Encrypting a file from Windows Explorer.

Should the GPGee program work correctly, after you right click on the file and choose the PK encrypt option, up will pop a small box, with a list of your keys. (GnuGP provided you with the KeyID when it was finished generating the key, but if this is new for you, there should only be one key available in GPGee anyway).

Choosing your key, in GPGee.

Choosing your key, in GPGee.

Check the one you just created and click O.K. Now, search in the same folder for a file with the identical name of the file you just created, but with .gpg extension, , i.e. the encrypted version of “test.doc” is named “test.doc.gpg” — see?

That .gpg file is the encrypted file. If it was a WordPad file, for instance, when you open it you will see only gibberish. That is because it is encrypted.

Please keep in mind that this process does not destroy the original file. It still remains in place. If you want the encrypted file to be the only copy, you’ll need to erase the original unencrypted file.

Unencrypting a file in this set-up is just as easy. Again, find the file in Windows Explorer, right click on the file, choose the GPGee mini-menu, choose verify/decrypt. It will then ask you for your password.

Encrypting a file using GPGee.

Enencrypting a file using GPGee.

Fill that in, and it unecrypts the original file, naming it as the original file. –Joab Jackson