Mã (python):
#!/usr/bin/python
import socket
socket.setdefaulttimeout(10)
s = socket.socket()
s.connect((“210.211.110.133″,21))
ans = s.recv(1024)
print ans
#!/usr/bin/python
import socket
socket.setdefaulttimeout(10)
s = socket.socket()
s.connect((“210.211.110.133″,21))
ans = s.recv(1024)
print ans
- Ví dụ đơn giản sử dụng thư viện socket trong python để lấy banner của một dịch vụ
- .setdefaulttimeout(10) là timeout của kết nối giữ trong 10 giây
- .connect(): kết nối đến IP 210.211.110.133 qua cổng FTP 21
- .recv(1024) là kết quả trả về của hàm connect, giới hạn trong 1024bit, kết quả được gán cho biến ans để in ra màn hình.
- Kết quả trả về như sau:
root@agent1 [~/py]# ./net.py
220———- Welcome to Pure-FTPd [privsep] [TLS] ———-
220-You are user number 1 of 50 allowed.
220-Local time is now 14:49. Server port: 21.
220-This is a private system – No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.