资源简介
用上面的接口可以查询自己的公网IP,本人已经搭了服务器!
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
using System.Runtime.InteropServices;
namespace QueryMyPublicNetworkIP
{
class Program
{
//TCP Client
public static string QueryMyPublicNetworkIPbyTcp()
{
string ipstr = string.Empty;
try
{
//1.Socket()
Socket s = new Socket(AddressFamily.InterNetwork SocketType.Stream ProtocolType.Tcp);
//2.Connect()
s.Connect(“148.70.217.194“ 1002);
//3.Send()
byte[] buf = new byte[50];
string pass = “Please tell me My Public Network IPAddress“;
buf = Encoding.ASCII.GetBytes(pass);
s.Send(buf);
////4.Receive()
byte[] data = new byte[50];
s.Receive(data);
ipstr = Encoding.ASCII.GetString(data).TrimEnd(‘\0‘);
- 上一篇:C# 图像处理、神经网络、遗传算法集
- 下一篇:Asp.net学生管理系统源码
评论
共有 条评论