Sunday 13 July 2014

C Program to Print its Own Source Code

Ever wondered how to write a C program to print its own source code? Well, here is the source code of a C program that when executed will print its own source code. In other words, the output of this program is exactly same as its source code.
Here’s the program:
#include<stdio.h>
char *program=”#include<stdio.h>%cchar *program=%c%s%c;%cvoid main()%c{%cprintf(program,10,34,program,34,10, 10,10,10);%c}”;
void main()
{
printf(program,10,34,program,34,10,10,10,10);
}

Block or Redirect Unwanted Websites Using HOSTS File

Block Websites Using Hosts FileThe hosts file is one of the interesting and useful feature of both Windows and Linux operating systems that provides many handy options in addressing network nodes. For instance, you can use thehosts file to block annoying ads, pop-ups, banners, porn sites, or even redirect one website to another.
In this post I will show you how to play around with the hosts file to accomplish some of the above mentioned jobs.

What is a hosts File?

The hosts file is just like any other computer file that is used by the operating system to map hostnames and domain names on to their corresponding IP addresses.
In other words, when you type “google.com” on your browser’s address bar, your computer will look for the hosts file to see if it contains the corresponding IP address for the domain name you typed (google.com). In case if no entry is present in the hosts file, the request is then passed on to the DNS (Domain Name System) server to obtain the IP address.

hosts File vs. DNS

When it comes to resolving the hostnames, the hosts file is given the first priority over the Domain Name System. In most cases, the hosts file remains unconfigured on the operating system and hence the DNS is used by the computer to resolve the domain names to their corresponding IP addresses.
However, if the hosts file is found to contain a valid entry for a given hostname or domain name, then this is picked up and used by the operating system.

Where is the hosts File Located?

Windows: In case of the Windows operating system, the hosts file is located at:
%systemroot%\system32\drivers\etc\hosts
NOTE: In most cases this should be: C:\Windows\System32\drivers\etc\hosts
Unix/Linux: In case of Linux it is located at:
/etc/hosts

How to Block a Website?

To block a specific website, all you have to do is just add a new entry for that site in the hosts file. I would prefer to backup the original file and create a new one instead of modifying it. So, if something goes wrong, you can just delete it and restore the original one! Well, here is a step-by-step procedure on how to create a new hosts file on Windows:
  1. Go to “My Computer” and you should see the “Menu bar” on top. In case of Vista and Win 7, just click “Alt” to unhide the “Menu bar”.
  2. Now in the menu bar, click on “Tools -> Folder Options”. In the “View” tab uncheck the option that says: “Hide extensions for known file types” and click on “OK”.
Windows Folder Options
  1. Open a new text pad (New Text Document.txt) and rename it to: hosts. You will get a pop-up message with a warning. Just click on “Yes”.
    Please note that the renamed file hosts should not have any extension such as 
    hosts.txt
    .
  2. Open the hosts file using the notepad. Now let us assume that you want to block the sitesFacebook and Youtube on your computer. For this all you have to do is add the following lines to your hosts file:
    127.0.0.1       facebook.com
    127.0.0.1       www.facebook.com
    127.0.0.1       youtube.com
    127.0.0.1       www.youtube.com
    Each entry should be placed on an individual line. The IP address and the hostname should be separated by a space or a tab. In this way, you can block any given website by just pointing it to the IP address 127.0.0.1.
  3. Navigate to %systemroot%\system32\drivers\etc. Here you should see the original hosts file, rename it to hosts_bak. Just copy and paste the new hosts file that you have created. That’s it. You’ve now successfully blocked those websites from loading on your computer.
    If you are using Vista/Win 7 you may have to take ownership of the original hosts file before renaming it.

How to Redirect a Website?

Suppose you want to redirect Friendster.com to Google.com, all you have to do is just add the following lines to your hosts file:
74.125.236.72       friendster.com
74.125.236.72       www.friendster.com
Here 74.125.236.72 is the IP address of Google.com. To find out the IP address of any given website, just go to command prompt and ping it. For example: ping google.com. You should get a ping response that displays the IP address as shown below:
Ping Test
From now on, whenever you type “friendster.com” on your browser, you will be redirected to “google.com”.

How does a hosts File work?

Whenever you block a website using the hosts file, you point it to the IP address 127.0.0.1 which in fact is the IP address of your own computer. In other words, the IP 127.0.0.1 points to your own computer and doesn’t exist outside.
So, whenever you type the URL of a website for which an entry is present in the hosts file, your computer will load the IP as 127.0.0.1 instead of the actual one and tries to establish a connection with this IP address (127.0.0.1) but fails. As a result the website doesn’t load at all.
The redirection of the website works by pointing the domain name of one website to the IP address of another website (as configured by the hosts file) instead of its original IP address. So, whenever you type friendster.com, it is pointed to Google.com’s IP address and thus, the Google page loads up instead of the actual page from friendster.com.

How to Block the Annoying Ads?

I have found a great solution to keep all the annoying ads, banners, pop-ups and other parasites at bay by using a pre-configured hosts called MVPS hosts file. This hosts file contains a long list of entries to block all those annoying ads and pop-ups that usually load while you are surfing the Internet. You can also receive regular updates on this to stay up-to-date. You can download MVPS hosts file from the link below:
If you are playing around with the hosts file and something goes wrong, just delete the hosts file itself and rename the original file from hosts_bak to hosts. This should bring back everything to normal. I hope this post on hosts file will help you block unwanted websites on your computer. Waiting for your comments.

How to Become a Hacker?

Most of us are very curious to learn Hacking and want to become a Hacker, but don’t know where to start. If you are in a similar situation, then this article will most likely guide you to reach your goal.
On a regular basis, I get a lot of emails where people ask me “How to Become a Hacker”. In fact, this question is not an easy one to answer, since hacking is not an art that can be mastered overnight. It requires knowledge, skills, creativity, dedication and of course the TIME. Everyone can become a hacker provided they learn it from the basics. So, if you wanna become a hacker, then all you need is a good source of knowledge that will guide you through various concepts of hacking from the basics.

What Skills do I Need to Become a Hacker?

In simple words, there is no magic to become a  Hacker. But, like anything else that is worthwhile, it takes dedication and willingness to learn. It is most important to have a basic knowledge of the topics such as operating system basics and it’s working, computer networks, computer security and of course programming. However, you need not be the expert in each or any of those topics mentioned. As you gain the basic knowledge of various branches of computer, you can choose any one as your favorite and advance in it.

What is the Best Way to Become a Hacker?

As said earlier, the best way to become a hacker is to start from the basics. You will have to master the basics to build a strong foundation. And once this is done, you’ll be in a position to explore new ideas and start thinking like a Hacker.
There exists tons of books on the market that will teach you hacking, but unfortunately, it requires a set of pre-established skills and knowledge to understand the concepts explained in those books. Also, most of them are not suitable for the beginners who doesn’t know anything about hacking.
Anyhow, I have found an excellent Book for the Beginners that will teach you hacking from the basics. This book is the first step to fulfil your dream of becoming a hacker. When I first read this book, I myself was surprised at how simple and easy it was laid out. I decided to introduce this book for all those enthusiasts as it can be the right source for the beginners who are interested to learn hacking from the basics. The good thing about this book is that, any one can understand the concepts presented here, without the need for any prior knowledge. This book is called:
Hacker's Underground Handbook
Learn Hacking
This book will take you from the core to the top. It will tell you how to hack in simple steps. Everything in this book is presented in a simple and effective manner. It is a great source for the beginner who would like to become a hacker. This will install a Hacker’s Mindset on you.
The following skills are uncovered in this book:
You will learn all the hacker underground tricks and learn to apply them in real world situations.
  1. You will be put into a hacker mindset so that you will learn to think like a Hacker.
  2. By learning how a hacker thinks and acts, you will be able to protect yourself from future hack attacks.
  3. You will acquire knowledge nonexistent to 99.9% of the people in the world!
  4. This underground handbook may get you interested in pursuing a career as an Ethical Hacker.
  5. This book is of great value for all those who have a dream to become a Hacker.
So what are you waiting for? Go grab your copy now from the following link:

Wait… This is not the end. Rather it is just the beginning of your journey. To become a hacker, all you need is dedication and hard work. I wish you all the best for your future success.

C Program Without a Main Function

C Program without a main functionHave you ever wondered how to write a C program without a main function? Can a C program execute with a main function? Is it possible to do that?
Well, the answer is YES! There can be a C program without a main function. Here is the source code of the program without a main function:
#include<stdio.h>
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
int begin()
{
printf(” hello “);
}
The above program runs perfectly fine even without a main function. But how? What’s the logic behind it? How can we have a C program working without a main function. Read on to find out the answer…
Here, we are using a preprocessor directive called #define with arguments to give an impression that the program runs without the main function. However, in reality it runs with a hidden main function in it.
NOTE: A Preprocessor is program which processes the source code before compilation.
The ‘##‘ operator is called the token pasting or token merging operator. That is, we can merge two or more characters with it. Now, look at the 2nd line of program:
#define decode(s,t,u,m,p,e,d) m##s##u##t
What is the preprocessor doing here? The macro decode(s,t,u,m,p,e,d) is being expanded as “msut” (The ## operator merges msu and t into msut). The logic is, when you pass (s,t,u,m,p,e,d) as argument it merges the 4th, 1st, 3rd and the 2nd characters (tokens).
Now, look at the third line of the program:
#define begin decode(a,n,i,m,a,t,e)
Here the preprocessor replaces the macro “begin” with the expansion decode(a,n,i,m,a,t,e). According to the macro definition in the previous line, the argument must be expanded so that the 4th, 1st, 3rd and the 2nd characters must be merged. In the argument (a,n,i,m,a,t,e) 4th, 1st, 3rd and the 2nd characters are ‘m’, ‘a’, ‘i’ and ‘n’.
So the third line “int begin” is replaced by “int main” by the preprocessor before the program is passed on to the compiler. That’s it.
The bottom line is that, there can never exist a C program without a main function. Here, we are just playing a gimmick that makes us believe that the program runs without the main, but there actually exists a hidden main function in the program. Here, we are using the proprocessor directive to intelligently replace the word “begin” by “main”. In simple words: int begin = int main.

How to Save Bookmarks from IE, Firefox, Chrome and Opera

How to Save BookmarksHow would you like to save your bookmarks from IE, Firefox, Opera and Google Chrome so that you can restore them in case if you need to re-install your operating system or move them from one computer to another? This post will show you how to save and restore bookmarks in simple steps.
Bookmarking the favorite web pages can save a lot of time as it becomes almost impossible to remember a list of favorite websites and their URLs. However, it can be really frustrating at times when you lose all those saved bookmarks in case if a computer crashes. Also, if you are a person who uses more than one computer then it becomes hard to copy all those bookmarks one by one manually. So, saving the bookmarks can be really handy in such situations. Here is how to to do it:

Saving a Bookmark file from Internet Explorer:

  1. From the File menu, select the option Import and Export.
  2. Select the option Export to a file and click on Next.
  3. In the next screen, select Favorites and click on Next.
  4. In the next screen, once again click on Favorites and then click on Next.
  5. Now choose the destination where you want to save your bookmarks and click on Export.
  6. In the next screen click on Finish.
Now you have successfully saved all your bookmarks in a .HTM file. You can use this file to later restore the bookmarks to either IE, Firefox or any other browser. To import the saved bookmarks from a file all you need to do is go to File menu, click on Import and Export, select the option Import from a file and proceed with the screen instructions.

Saving a Bookmark file from Firefox:

  1. From the Bookmarks menu on the top, select the option Organize Bookmarks.
  2. A window will pop-up. From this window, click on Import and Backup at the top and select the option Export HTML.
  3. Now choose the destination where you want to save the bookmark file and click on Save.
To restore this saved file, follow the step-1 and in step-2, select the option Import HTML instead of Export HTML and proceed.

Saving a Bookmark file from Google Chrome:

  1. From the Tools menu, select Bookmark Manager.
  2. Click the Organize menu in the manager.
  3. Select Export bookmarks.
  4. Select the location where you want your exported file to be saved, then click Save.
To restore the bookmarks, follow step-1, step-2 and in step-3 select Import bookmarks instead o of Export bookmarks and proceed.

Saving a Bookmark file from Opera:

  1. From the File menu, select the option Import and Export.
  2. Scroll over to the pull-down menu on the right and choose Export Bookmarks as HTML.
  3. On the next screen, choose the destination folder from the “Save in” menu text box at the top of the screen.
  4. Just click the Save button and you’re done.
I hope you like this post. If you have anything to say or have queries, please pass comments.