how to get esp32 ip address ,which is being connected to local network
You don't. You configure mDNS (as you already suggested in your question...!) and the client device then queries mDNS to find the device by the name you allocated it.

Look at the ESPmDNS library examples for how to use mDNS.

Edit: if you really want the IP, you can do WiFi.localIP() (station mode) or WiFi.softAPIP() (access point mode).