Biswajit,
Please elaborate what you're trying to do. I assume from your example code that you're trying to execute port checks towards Active Directory Domain Controllers.
Please keep in mind that every connection leaving your test machine to a remote IP will have the source IP of the network adapter that has an explicit route or default gateway. The localhost IP (127.0.0.1) is not used to communicate with remote machines (ever).
Best,
Daniel