| |

VerySource

 Forgot password?
 Register
Search
View: 734|Reply: 8

How to test if the other port is available?

[Copy link]

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-3 17:00:02
| Show all posts |Read mode
I have a set of IP addresses, and now I want to test if a port from these IPs is available? (This IP may also be offline)
Reply

Use magic Report

0

Threads

22

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 Invalid IP Address

Post time: 2020-5-16 18:00:02
| Show all posts
Simply use telnet ip port and write a batch

To program in VC, use tcp socket, connect port, wsagetlasterror (), and set to non-blocking mode.
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 United States

 Author| Post time: 2020-5-19 03:45:01
| Show all posts
CAsyncSocket m_sock;
// ...
m_sock.Create ();
if (m_sock.Connect (mReader [i] .m_strIP, 9898))
{
  success;
}
else {
    failure;
}

All entered, failed, but some IPs and ports are indeed useful. I use window media to enter the IP and port to play (that is, the IP and port are available)
Reply

Use magic Report

0

Threads

22

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 Invalid IP Address

Post time: 2020-6-3 23:15:01
| Show all posts
Before you debug the program, it is recommended that you telnet ip 9898 to see if you can connect,
Observe the following
1. Normally connected, you can send data through the keyboard
2. Normal connection, but immediately interrupted by the remote host
3. Can't connect. The port is indeed unavailable

Just judging the return value is not enough to determine

m_sock.Create();
if( m_sock.Connect(mReader[i].m_strIP,9898))
{
  success;
}
else{
  int errorcode=GetLastErro();
if (errorcode==WSAEWOULDBLOCK)
{
//When the socket is non-blocking, then the OnConnect message will be corresponding. In this message response function, you can determine whether to connect, and then disconnect to connect the next IP and port, do not directly loop
}
else
{
// Failed; it is recommended to obtain errorcode to judge the specific code
}
}
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-6-8 17:00:02
| Show all posts
m_sock.Connect(mReader[i].m_strIP,9898) is false
But the IP and port are indeed available, the IP is online.
The IP does not run any socket program
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-6-10 20:45:01
| Show all posts
Because your IP is not bound to the server, your peer machine is not a server. Your machine is just a client. Certainly not connected
Reply

Use magic Report

0

Threads

22

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 Invalid IP Address

Post time: 2020-6-13 12:00:01
| Show all posts
remote ip If the remote host is not listening on this IP and port, how can it be available? The so-called IP is online, but you use ping to send icmp packets, regardless of the port
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-6-20 10:15:02
| Show all posts
How to send icmp package with program?
Reply

Use magic Report

0

Threads

22

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 Invalid IP Address

Post time: 2020-7-1 17:45:01
| Show all posts
socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
Specify the socket as the original socket, and the ICMP protocol, and then package according to the ICMP protocol, sendto,
You can search. A lot of similar code
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list