1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 #include <arpa/inet.h>
 5 
 6 
 7 void port_parse(char *str,short * port) {
 8     int a,b,c,d,e,f;
 9     char *p = str;
10     
11     for(int i=0;i<strlen(str);i++)
12     {
13         if((*p >= '0')&&(*p <= '9'))
14         {
15             if(6 == sscanf(p,"%d,%d,%d,%d,%d,%d",&a,&b,&c,&d,&e,&f)){
16                 {
17                     *port = (e<<8)+f;
18                     printf("port %d\n",*port);
19                 }
20                 return;
21             }
22         }
23         p++;
24     }
25 }
26 
27 int main() {
28     char * p1 = "227 Entering Passive Mode (59,37,162,9,19,157).";
29     char str[50];
30     strcpy(str,p1);
31     short port;    
32     port_parse(str,&port);
33     return 0;
34 }

//借用后,记得点个赞!