A wireless sensor network (WSN) consists of a number of tiny, low-cost, and resource-constrained sensor nodes, but is often deployed in unattended and harsh environments to perform various monitoring tasks. Security is important for many sensor network applications. As a result, WSNs are susceptible to many application-dependent and application-independent attacks. WSNs are often deployed in harsh environments, where an attacker node can physically capture some of the sensor nodes. Once a sensor node is captured then the attacker node can collect all the credentials like keys, identities etc. The attacker can modify the message and replicate in order to overhear the messages or interrupt the functionality of the sensor networks. IPD and PSD are proposed as an optimized localization algorithm for defending against the node replication attacks. Each node in the localized algorithm can communicate only with its one-hop neighbors. The node can meet again, it can be compared with the first node, previous node location, and attack replication node.