获取IP地址的方法取决于你是在服务器端还是客户端。
服务器端
在服务器端,你可以使用不同的编程语言来实现获取IP地址的功能。
Python
```python
import socket
def get_ip_address():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
doesn't even have to be reachable
s.connect(('10.254.254.254', 1))
IP = s.getsockname()[0]
except Exception:
IP = '127.0.0.1'
finally:
s.close()
return IP
print(get_ip_address())
```
Java
```java
import java.net.InetAddress;
public class Main {
public static void main(String[] args) {
try {
InetAddress ip = InetAddress.getLocalHost();
System.out.println("IP Address: " + ip.getHostAddress());