Saturday, December 11, 2010

javascript Date difference in days

Many times it is required to compare two Date object and get the difference between the dates in days. Following javascript function will get you the difference in days

Date.getDaysDifference = function(fromDate,toDate)
{
   fromDate = new Date(fromDate.getFullYear(),fromDate.getMonth(),fromDate.getDate());
   toDate = new Date(toDate.getFullYear(),toDate.getMonth(),toDate.getDate());
   return ((toDate-fromDate)/86400000); //Total millisends in day =1000*60*60*24
}

Date.prototype.getDaysDifference = function(toDate)
{
   return Date.getDaysDifference(this,toDate);
}


Usage Example

var fromDate= new Date(2010,1,1);
var toDate= new Date(); //today's date
alert(Date.getDaysDifference(fromDate,toDate));
//or
alert(fromDate.getDaysDifference(toDate));

Friday, November 19, 2010

Registry Trick: Multiple instances of yahoo messenger

Have you ever felt the need of using multiple yahoo messenger instance from the same machine? Yes, then here is the way to do it.

•Click start then run. Write regedit, press enter
•Goto "HKEY_CURRENT_USER\Software\Yahoo\Pager\Test"
•Create a DWORD registry value named "Plural" by right clicking the right hand side window.
•Double click the new DWORD entry and set the value to 1
Now you remain online with two or more different yahoo ids at the same time.

source: http://www.thinkdigit.com/forum/showthread.php?t=55350

Sunday, November 14, 2010

MAC Spoofing

What is MAC address?

Each and every network device in this world have a unique MAC (Medium access control) address. A MAC address is a 6 byte address which is often displayed in XX-XX-XX-XX-XX-XX where each X is a hex digit like 00-1D-2F-BE-BA-01 or AE-01-AE-29-BE-0F.

In windows we can get the mac address by using ipconfig /all command or using getmac command. These commands will return you the mac address each NIC (network interface card) connected to the computer. E.g.



What is MAC Spoofing?

Changing of MAC address for making a node (computer or any device) get the identity of other node(desiguse) in the network is know as MAC spoofing. By changing the MAC address we spoof the network routing device like switch and router. Many switch and router provides a interface using which administrator can restrict the nodes in the network, typically called as MAC address filtering. Administrator can there define the MAC address of devices which are allowed to connect to the network and thus prevents conectivity of unidentified node to the network.



How to change a MAC address?

In windows we can change the MAC address using multiple ways.

Method1: Using network card configuration window. Goto Control Panel>Network Connections select the network right click on it select properties this will open up Network connection properties.
Now click on the configuration button this will open the NIC device (using which network is communicating) properties which can be also opened via device manager. Select the Advanced tab from the NIC device property window and select the "Network Address" from the property list and set its new value to any desired valid MAC address.










Wednesday, November 10, 2010

Javascript injections and Javascript debugging techniques.

Javascript injection is a technique of executing javascript in already loaded page in a browser. JS injections are commonly used for executing XSS(cross side scripting), SQL injection, for bypassing client side validations and also for debugging javascript in webpages.
There are many approach by which we can execute a javascript injection, few of them are shown here

1. Query inside address bar (works in almost all brower): Like we write javascript statement in anchor href attribute which gets executed on click of anchor. In the same way we can put javascript in address bar and execute them.

E.g. Copy and paste below given line in address bar and press enter
javascript: alert("This is a simple js injection.");
we can also add a js function using js injection like
javascript: void(window.myfunc = function(){alert("This alert is shown via myfunc function.");}); func();

2. Using browser js debugger: Almost all modern browser have there debugger for the web developers. Like IE Developer Tools (which comes with IE8 and onwards), firebug in Mozilla, Dragonfly in Opera. These all tools have a javascipt console where we can write javascript and execute them. Using these tools we can even write multiline javascript.