Setting address of whois service for ruby whois gem - ruby

Using the ruby whois gem, how do I set the server address of the whois service?
Setting the bind_host, I get an error.
> whois_client = Whois::Client.new(bind_host: "192.0.47.59", bind_port: 43)
=> #<Whois::Client:0x00000008188e7e50 #timeout=10, #settings={:bind_host=>"192.0.47.59", :bind_port=>43}>
> record = whois_client.lookup('wandajackson.com')
Whois::ConnectionError: Errno::EADDRNOTAVAIL: Can't assign requested address - bind(2) for "192.0.47.59" port 43
from (irb):4

I'm pretty sure bind_host doesn't refer to the host used for the whois lookup, but instead refers to the adapter binding on the server running your code. By default it binds to 0.0.0.0, or all the adapters on the local server.
If you want to have the whois gem use a custom server address for looking up whois information then it appears that you have to specify it in one of the following ways:
# Define a server for the .com TLD
Whois::Server.define :tld, "com", "your.whois.server.address"
Whois.whois("google.com")
# Define a new server for an range of IPv4 addresses
Whois::Server.define :ipv4, "10.0.0.0/8", "your.whois.server.address"
Whois.whois("10.0.0.1")
# Define a new server for an range of IPv6 addresses
Whois::Server.define :ipv6, "2001:2000::/19", "your.whois.server.address"
Whois.whois("2001:2000:85a3:0000:0000:8a2e:0370:7334")
These examples were taken from https://www.rubydoc.info/gems/whois/Whois/Server.

Related

can't start solana validator node,can't connect

I have used SSR, and the viewer can access the node
get_cluster_shred_version failed: 108.160.170.41:8001, connection timed out
.....
[2022-05-07T01:25:37.984950553Z INFO solana_validator] Contacting 128.242.240.212:8001 to determine the validator's public IP address
....
Unable to determine the validator's public IP address
This error happens when it isn't possible for the software to figure out what its public ip address is for the gossip protocol at this line: https://github.com/solana-labs/solana/blob/8d0134e0fdede539cf8ab89ef0ce794f1d41f9dc/validator/src/main.rs#L2819
To be explicit, pass --gossip-host and --gossip-port, ie:
$ solana-validator <all of your previous args> --gossip-host YOUR_IP_HERE --gossip-port 8001
Note that you don't need to have your gossip port at 8001, but it's a convention.

JMeter - Listen to a port on a given IP

I want to run a jmeter test, which listens to a port on a given ip, and prints the messages which are being sent to that port. I have tried using this:
SocketAddress inetSocketAddress = new InetSocketAddress(InetAddress.getByName("<client ipAddress>"),<port number>);
def server = new ServerSocket();
server.bind(inetSocketAddress);
while(true) {
server.accept { socket ->
log.info('Someone is connected')
socket.withStreams { input, output ->
def line = input.newReader().readLine()
log.info('Received message: ' + line)
}
log.info("Connection processed")
}
}
But this is giving me error - "Cannot assign requested address: JVM_Bind
"
Is there any alternate way to approach this? Or what changes do i need to do for the current approach to work?
You copied and pasted this code from the right place and it should work just fine. Evidence:
as per the BindException documentation
Signals that an error occurred while attempting to bind a socket to a local address and port. Typically, the port is in use, or the requested local address could not be assigned.
So I can think of 2 options:
Your <client ipAddress> is not correct and cannot be resolved.
Something is already running on the <port number>, you cannot have 2 applications listening to the same port, the first one will be successful and another one will fail
More information:
Fixing java.net.BindException: Cannot assign requested address: JVM_Bind in Tomcat, Jetty
Apache Groovy - Why and How You Should Use It

Ruby and Bonjour

I am new to ruby and its library, but how do i combine DNSSD and TCPServer together?
I know i can register DNSSD service via
registration = DNSSD.register("My Files", hostname, "local.", port)
And I can create a DNSSD service for my TCPServer this way, but how do i specify the hostname (service name) as the above?
server = TCPServer.open(port)
DNSSD.announce server, 'my awesome HTTP server'
I want to broadcast my server, so that the client can resolve the DNSSD service and establish a connection.
Pardon me if thats a stupid question.
I manage to setup it up via
Register a DNSSD aka Bonjour Service
DNSSD.register("", hostname, "local.", port) do |register_reply|
puts "Registration result: #{register_reply.inspect}"
end
Setup TCPServer to listen on the same port
blackjack = TCPServer.open("",port)
loop do
socket = blackjack.accept
peeraddr = socket.peeraddr
puts "Connection from %s:%d" % socket.peeraddr.values_at(2, 1)
end

Ruby ODBC with remote database

I am working on an application that connects to a legacy database, Eloquence, through ODBC and SQL/R. I set up my server with UnixODBC and setup the drivers and datasources as follows:
File /etc/odbcinst.ini
[SQLR]
Description=SQLR for Elqouence
Driver=/opt/sqlr/lib/libsqlrodbc.so
Driver64=/opt/sqlr/lib64/libsqlrodbc64.so
FileUsage = 1
File /etc/odbc.ini
[reservations]
Description = SQLR datasource for RES database
Driver = SQLR
Database = res
Servername = eloq-dev
Port = 8003
UserName = sqlrodbc
I confirmed that I can connect to the datasource by running isql reservations and I ran a couple of queries to make sure. No issues. Then I connected my Ruby code up to the database using the ODBC gem and the following code:
require 'rdbi-driver-odbc'
RDBI.connect :ODBC, db: "reservations"
Which outputs the following error:
Unable to connect to host.
Host 127.0.0.1, Service sqlrodbc
errno 111: Connection refused
ODBC::Error: 08001 (3047) [unixODBC][Marxmeier][SQL/R ODBC Client]connection failure
I'm concerned that it's using 127.0.0.1 as the host even though the eloq-dev hostname is set in file /etc/hosts to a different address. I'm also concerned that isql works, but the ODBC gem doesn't.
Additionally, when I use the tcpdump command, the only output related to my connection is this:
tcpdump -i lo
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
18:38:39.688264 IP localhost.50447 > localhost.mcreport: Flags [S], seq 3355035364, win 43690, options [mss 65495,sackOK,TS val 1655798115 ecr 0,nop,wscale 7], length 0
18:38:39.688280 IP localhost.mcreport > localhost.50447: Flags [R.], seq 0, ack 3355035365, win 0, length 0
No packets are going out over the network at all.
I've also changed my code to use RDBI instead of Ruby-ODBC, but I have the same issue.
My issue was ultimately twofold. I was connecting to Eloquence and SQL/R over a VPN connection which wasn't as stable as I thought and so connections were dropping as a result.
The other issue was that SQL/R uses Server instead of ServerName and Service instead of Port in the odbc.ini file.
Once I stabilized my VPN and fixed the odbc.ini file I was able to connect without issue.

Opscode Nagios Cookbook Not pulling Cloud IP address

I am trying to generate the nagios hosts.cfg file from the standard opscode nagios cookbook. Using the standard recipe I am continually getting the same errors from the following lines:
Chef::Mixin::Template::TemplateError (undefined method `[]' for nil:NilClass) on line #19:
17: if node['cloud'].nil? && !n['cloud'].nil?
18: ip = n['cloud']['public_ipv4'].include?('.') ? n['cloud']['public_ipv4'] : n['ipaddress']
19: elsif !node['cloud'].nil? && n['cloud']['provider'] != node['cloud']['provider']
20: ip = n['cloud']['public_ipv4'].include?('.') ? n['cloud']['public_ipv4'] : n['ipaddress']
21: else
22: ip = n['ipaddress']
The full File is here:
http://pastebin.com/FqcdUnSE
Notations on the original file were as follows:
<% # decide whether to use internal or external IP addresses for this node
# if the nagios server is not in the cloud, always use public IP addresses for cloud nodes.
# if the nagios server is in the cloud, use private IP addresses for any
# cloud servers in the same cloud, public IPs for servers in other clouds
# (where other is defined by node['cloud']['provider'])
# if the cloud IP is nil then use the standard IP address attribute. This is a work around
# for OHAI incorrectly identifying systems on Cisco hardware as being in Rackspace
Instead of trying to fix this, I did the following workaround:
define host {
use server
address <%= node['ipaddress'] %>
host_name <%= node[node['nagios']['host_name_attribute']] %>
hostgroups <%= node['nagios']['server_role'] %>,<%= node['os'] %>
}
This worked instead of using the cloud ip configs.

Resources