A method for setting up a wireless network connection in a WiFi network, comprising: sending, by a first device, a probe message to a second device by using a first transmit power, wherein the probe message is used to instruct the second device to send a third response message by using a second transmit power, receiving, by the first device, the third response message, wherein the third response message carries a first receive power when the second device receives the probe message, and obtaining, by the first device and through detection, a second receive power when receiving the third response message; obtaining, by the first device and according to the first transmit power and the first receiver power or according to the second transmit power and the second receive power, a path loss between the first device and the second device; and when determining, according to the path loss, that a distance between the first device and the second device is within a preset distance range, sending, by the first device, network configuration information needed for accessing a wireless network to the second device, so that the second device sets up a connection with the wireless network according to the network configuration information; wherein: the path loss obtained by the first device according to the first transmit power and the first receive power is a first path loss; the path loss obtained by the first device according to the second transmit power and the second receive power is a second path loss; after the determining, by the first device and according to the path loss, that the distance between the first device and the second device is within the preset distance range and before the sending, by the first device, the network configuration information needed for accessing the wireless network to the second device, the method further comprises: comparing, by the first device, the second path loss with the first path loss, and if a loss variation value between the two is within a preset loss variation value range, identifying the second device as a real device. sending, by a first device, a probe message to a second device by using a first transmit power, wherein the probe message is used to instruct the second device to send a third response message by using a second transmit power, receiving, by the first device, the third response message, wherein the third response message carries a first receive power when the second device receives the probe message, and obtaining, by the first device and through detection, a second receive power when receiving the third response message; obtaining, by the first device and according to the first transmit power and the first receiver power or according to the second transmit power and the second receive power, a path loss between the first device and the second device; and when determining, according to the path loss, that a distance between the first device and the second device is within a preset distance range, sending, by the first device, network configuration information needed for accessing a wireless network to the second device, so that the second device sets up a connection with the wireless network according to the network configuration information; wherein: the path loss obtained by the first device according to the first transmit power and the first receive power is a first path loss; the path loss obtained by the first device according to the second transmit power and the second receive power is a second path loss; after the determining, by the first device and according to the path loss, that the distance between the first device and the second device is within the preset distance range and before the sending, by the first device, the network configuration information needed for accessing the wireless network to the second device, the method further comprises: the path loss obtained by the first device according to the first transmit power and the first receive power is a first path loss; the path loss obtained by the first device according to the second transmit power and the second receive power is a second path loss; after the determining, by the first device and according to the path loss, that the distance between the first device and the second device is within the preset distance range and before the sending, by the first device, the network configuration information needed for accessing the wireless network to the second device, the method further comprises: comparing, by the first device, the second path loss with the first path loss, and if a loss variation value between the two is within a preset loss variation value range, identifying the second device as a real device.