An Optimal Method for Detecting Internal and External Intrusion in MANET