Sending data to hotspot IP with ESP32

I’m using ESP32.

ESP32 is connected to laptop hotspot via builtin ESP32 WiFi. How can I get Hotspot local IP address and port?

The main aim to to then connect to hotspot IP so, then I can use WiFiclient to send data to laptop WiFi Hotspot without running any localhost like xampp.

Currently my guess is WiFi.dnsIP(0) returns Hotspot IP address because it’s value is 192.168.137.1 but I’m clueless regarding port.

I’m also interested in getting every hotspot properties possible.

Thank you


The main code used for connecting:-

#define d(x) Serial.print(x)
#define D(x) Serial.println(x)

void WifiConct()
{
  d("Connecting\n");
  WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info){D("\nConnected");}, SYSTEM_EVENT_STA_CONNECTED);
  WiFi.onEvent(
  [](WiFiEvent_t event, WiFiEventInfo_t info)
  {
    d("Local IP : ");
    D(WiFi.localIP());
    d("Subnet Mast : ");
    D(WiFi.subnetMask());
    d("Gateway IP : ");
    D(WiFi.gatewayIP());
    d("DNS 1 : ");
    D(WiFi.dnsIP(0));
    d("DNS 2 : ");
    D(WiFi.dnsIP(2));
    ip=WiFi.dnsIP(0);
    d("ip : ");
    D(ip);
    if(client.connect(ip, 80))
      D("Connected to client!!!");
    else
      D("Connection failed!!!");
  }, SYSTEM_EVENT_STA_GOT_IP);
  WiFi.begin(ssid, pass);
  d("Waiting for SSID : ");
  D(ssid);
  D(WiFi.status());
  loopW();
}

void loopW()
{
  while((WiFi.status()-3)<0)
  {
    Blnk();
    d(".");
  }
}

Output on serial:-

20:01:50.153 -> Connecting
20:01:50.153 -> Waiting for SSID : MLap
20:01:50.153 -> 3
20:01:50.153 -> Connection failed!!!
20:01:50.887 -> 
20:01:50.887 -> Connected
20:01:50.887 -> 
20:01:50.887 -> Connected
20:01:50.887 -> Local IP : 192.168.137.18
20:01:50.887 -> Subnet Mast : 255.255.255.0
20:01:50.887 -> Gateway IP : 192.168.137.1
20:01:50.887 -> DNS 1 : 192.168.137.1
20:01:50.887 -> DNS 2 : 0.0.0.0
20:01:50.887 -> ip : 192.168.137.1
20:02:08.565 -> Connection failed!!!
20:02:08.565 -> Local IP : 192.168.137.18
20:02:08.565 -> Subnet Mast : 255.255.255.0
20:02:08.565 -> Gateway IP : 192.168.137.1
20:02:08.565 -> DNS 1 : 192.168.137.1
20:02:08.565 -> DNS 2 : 0.0.0.0
20:02:08.565 -> ip : 192.168.137.1
20:02:27.068 -> Connection failed!!!