LoginSignup
0
0

More than 3 years have passed since last update.

Ruby で DistIP,DistPort,SourceIP,SourcePort を指定して Tcp 通信を行うコード

Posted at

きっかけ

通信の検証で5-tupleの影響を受けているのか確認する必要があった

5-tupleとは

IPヘッダに存在する5つの要素のことで

1.Source IP
送信元アドレス
2.Destination IP
宛先アドレス
3.Source Port
送信元ポート
4.Destination Port
宛先ポート
5.Protocol
プロトコル

を指す

tcp.rb
require 'socket'

distIp     = "111.111.111.111"
distPort   = 80
sourceIp   = "222.222.222.222"
sourcePort = 100

begin
  s = TCPSocket.open(distIp,distPort,sourceIp,sourcePort)
  s.print "GET / HTTP/1.0\r\n\r\n"
  print s.read
ensure
  s.close if s
end

メモ

サーバに送信している部分で下記のヘッダー情報が必要かもしれないと思った

tcp.rb
  s.print "GET / HTTP/1.0\r\nUser-Agent: curl/7.19.7\r\nHost: localhost\r\nAccept: */*\r\nConnection: close\r\n\r\n"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0